Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
finwe opened this issue Nov 3, 2020 · 3 comments
Closed

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

finwe opened this issue Nov 3, 2020 · 3 comments

Comments

@finwe
Copy link

finwe commented Nov 3, 2020

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
@dg
Copy link
Member

dg commented Nov 3, 2020

Looks like you haven't loaded netteforms.js

@finwe
Copy link
Author

finwe commented Nov 3, 2020

Yes, I haven't, knowingly.

@finwe
Copy link
Author

finwe commented Nov 3, 2020

Anyway, the filter isn't applied to the value even with netteforms.js - how could it convert the PHP closure to javascript?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants