diff --git a/sources/Form/Field/MultipleChoicesField.php b/sources/Form/Field/MultipleChoicesField.php index 20ab99749..adaf12176 100644 --- a/sources/Form/Field/MultipleChoicesField.php +++ b/sources/Form/Field/MultipleChoicesField.php @@ -218,14 +218,16 @@ abstract class MultipleChoicesField extends Field $this->SetValid(true); $this->EmptyErrorMessages(); - if (count($this->currentValue) > 0) { - foreach ($this->currentValue as $sCode => $value) { - if (utils::IsNullOrEmptyString($value)) { - continue; - } - if (false === array_key_exists($value, $this->aChoices)) { - $this->SetValid(false); - $this->AddErrorMessage("Value ({$value}) is not part of the field possible values list"); + if ($this->GetReadOnly() === false) { + if (count($this->currentValue) > 0) { + foreach ($this->currentValue as $sCode => $value) { + if (utils::IsNullOrEmptyString($value)) { + continue; + } + if (false === array_key_exists($value, $this->aChoices)) { + $this->SetValid(false); + $this->AddErrorMessage("Value ({$value}) is not part of the field possible values list"); + } } } } diff --git a/sources/Form/Field/SelectObjectField.php b/sources/Form/Field/SelectObjectField.php index df547f977..1d70a437d 100644 --- a/sources/Form/Field/SelectObjectField.php +++ b/sources/Form/Field/SelectObjectField.php @@ -250,22 +250,24 @@ class SelectObjectField extends Field } public function Validate() { - $sCurrentValueForExtKey = $this->currentValue; - if (utils::IsNotNullOrEmptyString($sCurrentValueForExtKey) && ($sCurrentValueForExtKey !== 0)) { - $oSearchForExistingCurrentValue = $this->oSearch->DeepClone(); - $oSearchForExistingCurrentValue->AddCondition('id', $sCurrentValueForExtKey, '='); - $oCheckIdAgainstCurrentValueExpression = new BinaryExpression( - new FieldExpression('id', $oSearchForExistingCurrentValue->GetClassAlias()), '=', new ScalarExpression($sCurrentValueForExtKey) - ); - $oSearchForExistingCurrentValue->AddConditionExpression($oCheckIdAgainstCurrentValueExpression); - $oSetForExistingCurrentValue = new DBObjectSet($oSearchForExistingCurrentValue); - $iObjectsCount = $oSetForExistingCurrentValue->CountWithLimit(1); + if ($this->GetReadOnly() === false) { + $sCurrentValueForExtKey = $this->currentValue; + if (utils::IsNotNullOrEmptyString($sCurrentValueForExtKey) && ($sCurrentValueForExtKey !== 0)) { + $oSearchForExistingCurrentValue = $this->oSearch->DeepClone(); + $oSearchForExistingCurrentValue->AddCondition('id', $sCurrentValueForExtKey, '='); + $oCheckIdAgainstCurrentValueExpression = new BinaryExpression( + new FieldExpression('id', $oSearchForExistingCurrentValue->GetClassAlias()), '=', new ScalarExpression($sCurrentValueForExtKey) + ); + $oSearchForExistingCurrentValue->AddConditionExpression($oCheckIdAgainstCurrentValueExpression); + $oSetForExistingCurrentValue = new DBObjectSet($oSearchForExistingCurrentValue); + $iObjectsCount = $oSetForExistingCurrentValue->CountWithLimit(1); - if ($iObjectsCount === 0) { - $this->SetValid(false); - $this->AddErrorMessage("Value $sCurrentValueForExtKey does not match the corresponding filter set"); + if ($iObjectsCount === 0) { + $this->SetValid(false); + $this->AddErrorMessage("Value $sCurrentValueForExtKey does not match the corresponding filter set"); - return $this->GetValid(); + return $this->GetValid(); + } } }