Skip to content

Form field filter not taken into account for frontend validation #259

@finwe

Description

@finwe

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.

shot_201103_185227

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions