-
-
Notifications
You must be signed in to change notification settings - Fork 151
Closed
Description
Version: 3.0.7
Bug Description
Trying to filter form field value based on this doc chapter. https://doc.nette.org/cs/3.0/form-validation#toc-uprava-vstupu
As addRule(Form::PATTERN adds a HTML attribute pattern, the input of the field, which would cleanup the value to pass the pattern test is not applied before HTML5 validation in the browser, the form cannot be submitted.
Steps To Reproduce
$form->addText('code', 'Kód e-receptu')
->setRequired(true)
->addFilter(function ($value) {
return Strings::lower(Strings::trim(Strings::replace($value, '/[- ]/', '')));
})
->addRule(Form::PATTERN, 'Kód musí obsahovat právě 12 číslic nebo písmen', '/^[a-z0-9]{12}$/');
The example from the documentation will also not pass the HTML5 validation when containing spaces.
Expected Behavior
It is possible to submit the form.
Possible Solutions
- The HTML5 validation is not applied on fields having a filter, the form is validated on the backend.
- The doc is updated to show how to mitigate this
Metadata
Metadata
Assignees
Labels
No labels
