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

@@ -27,7 +27,9 @@ use Combodo\iTop\Application\UI\Base\Component\Input\Select\SelectOptionUIBlockF
use Combodo\iTop\Application\UI\Base\Component\Input\SelectUIBlockFactory;
use Combodo\iTop\Application\UI\Base\Layout\UIContentBlockUIBlockFactory;
use Combodo\iTop\Form\Field\SelectObjectField;
use Combodo\iTop\Form\Validator\AbstractRegexpValidator;
use Combodo\iTop\Form\Validator\MandatoryValidator;
use Combodo\iTop\Form\Validator\NotEmptyExtKeyValidator;
use Combodo\iTop\Renderer\BlockRenderer;
use Combodo\iTop\Renderer\FieldRenderer;
use DBObjectSet;
@@ -245,16 +247,19 @@ JS
$oOutput->AddHtml((BlockRenderer::RenderBlockTemplates($oBlock)));
// JS Form field widget construct
$aValidators = array();
foreach ($this->oField->GetValidators() as $oValidator)
{
if ($oValidator::GetName() == 'notemptyextkey')
{
foreach ($this->oField->GetValidators() as $oValidator) {
if (false === ($oValidator instanceof AbstractRegexpValidator)) {
// no JS counterpart, so skipping !
continue;
}
if ($oValidator instanceof NotEmptyExtKeyValidator) {
// The autocomplete widget returns an empty string if the value is undefined (and the select has been aligned with this behavior)
$oValidator = new MandatoryValidator();
}
$aValidators[$oValidator::GetName()] = array(
'reg_exp' => $oValidator->GetRegExp(),
'message' => Dict::S($oValidator->GetErrorMessage())
'message' => Dict::S($oValidator->GetErrorMessage()),
);
}
$sValidators = json_encode($aValidators);