N°6414 Validator refactoring

New AbstractValidator class, with new method Validate
All existing validators are now children of AbstractRegexpValidator
Handle validators JS counterparts in renderers : only regexp validators are implemented client side
This commit is contained in:
Pierre Goiffon
2023-06-29 10:41:51 +02:00
parent 52049b7837
commit 6606af71ff
26 changed files with 348 additions and 247 deletions

View File

@@ -22,6 +22,7 @@ namespace Combodo\iTop\Form\Field;
use BinaryExpression;
use Closure;
use Combodo\iTop\Form\Validator\AbstractValidator;
use Combodo\iTop\Form\Validator\NotEmptyExtKeyValidator;
use ContextTag;
use DBObjectSet;
@@ -168,38 +169,15 @@ class SelectObjectField extends Field
return $this;
}
/**
* @inheritDoc
*/
public function SetMandatory(bool $bMandatory)
protected function GetMandatoryValidatorInstance(): AbstractValidator
{
// Before changing the property, we check if it was already mandatory. If not, we had the mandatory validator
if ($bMandatory && !$this->bMandatory)
{
$this->AddValidator(new NotEmptyExtKeyValidator());
}
if (!$bMandatory)
{
foreach ($this->aValidators as $iKey => $oValue)
{
if ($oValue::Getname() === NotEmptyExtKeyValidator::GetName())
{
unset($this->aValidators[$iKey]);
}
}
}
$this->bMandatory = $bMandatory;
return $this;
return new NotEmptyExtKeyValidator();
}
/**
* @return \DBSearch
*/
public function GetSearch()
{
public function GetSearch() {
return $this->oSearch;
}