diff --git a/sources/Form/Field/MultipleChoicesField.php b/sources/Form/Field/MultipleChoicesField.php index adaf12176..f7791acb2 100644 --- a/sources/Form/Field/MultipleChoicesField.php +++ b/sources/Form/Field/MultipleChoicesField.php @@ -20,6 +20,7 @@ namespace Combodo\iTop\Form\Field; use Closure; +use ContextTag; use utils; /** @@ -211,14 +212,13 @@ abstract class MultipleChoicesField extends Field return $this; } - /** - * @inheritDoc - */ public function Validate() { $this->SetValid(true); $this->EmptyErrorMessages(); - if ($this->GetReadOnly() === false) { + if ((ContextTag::Check(ContextTag::TAG_REST)) && ($this->GetReadOnly() === false)) { + // Only doing the check when coming from the REST API, as the user portal might send invalid values (see VerifyCurrentValue() method below) + // Also do not check read only fields, are they are send with a null value when submitting request template from the console if (count($this->currentValue) > 0) { foreach ($this->currentValue as $sCode => $value) { if (utils::IsNullOrEmptyString($value)) { diff --git a/sources/Form/Field/SelectObjectField.php b/sources/Form/Field/SelectObjectField.php index 63058268b..2797bb03a 100644 --- a/sources/Form/Field/SelectObjectField.php +++ b/sources/Form/Field/SelectObjectField.php @@ -23,6 +23,7 @@ namespace Combodo\iTop\Form\Field; use BinaryExpression; use Closure; use Combodo\iTop\Form\Validator\NotEmptyExtKeyValidator; +use ContextTag; use DBObjectSet; use DBSearch; use FieldExpression; @@ -250,7 +251,9 @@ class SelectObjectField extends Field } public function Validate() { - if ($this->GetReadOnly() === false) { + if ((ContextTag::Check(ContextTag::TAG_REST)) && ($this->GetReadOnly() === false)) { + // Only doing the check when coming from the REST API, as the user portal might send invalid values (see VerifyCurrentValue() method below) + // Also do not check read only fields, are they are send with a null value when submitting request template from the console $sCurrentValueForExtKey = $this->currentValue; if (utils::IsNotNullOrEmptyString($sCurrentValueForExtKey) && ($sCurrentValueForExtKey !== 0)) { $oSetForExistingCurrentValue = $this->GetObjectsSet(); @@ -272,6 +275,9 @@ class SelectObjectField extends Field * Resets current value if not among allowed ones. * By default, reset is done ONLY when the field is not read-only. * + * Called conditionally from {@see \Combodo\iTop\Portal\Form\ObjectFormManager::Build} + * This check isn't in the Validate method as we don't want to check for untouched and invalid values (value was set in the past, it is now invalid, but the user didn't change it) + * * @param boolean $bAlways Set to true to verify even when the field is read-only. * * @throws \CoreException