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

netteForms.js: "Please enter a valid value." error on conditionally required number input #252

Closed
xificurk opened this issue Jul 29, 2020 · 0 comments

Comments

@xificurk
Copy link
Contributor

Version: 3.0.x

Bug Description

Client side validation displays confusing error message "Please enter a valid value" when number input is conditionally required and contains an invalid value. Also, this error message is hardcoded in netteForms.js and cannot be localized.

Steps To Reproduce

Create form with conditonally required number input:

$checkbox = $form->addCheckbox('checkbox');
$number = $form->addInteger('number');
$number->addConditionOn($checkbox, Form::FILLED)->setRequired();
$number->addRule(Form::RANGE, 'Select a number from 1 to 10', [1, 10]);

Display the from in browser, check the checkbox and type "666" in the number input (i.e. a value outside of allowed range). When the user attempts to submit the form, "Please enter a valid value" validation error message is displayed.

Expected Behavior

Client side validation error message "Select a number from 1 to 10." is displayed.

Analysis and Possible Solution

This is the problematic code block: https://github.com/nette/forms/blob/master/src/assets/netteForms.js#L188
When checkbox is checked, the number input is required to be filled - number input is considered filled even with invalid value, so the validation succeeds, but then it runs into the mentioned code and the hardcoded error is returned.

I suspect the whole code block could be removed. It looks like all the possible native invalid states are correctly handled in specific validators. I can't really think of a valid use case for which this check in netteForms.js is necessary.

@dg dg closed this as completed in 0f3371c Jul 31, 2020
dg added a commit that referenced this issue Jul 31, 2020
…nested checking in validateControl() [Closes #252]
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

1 participant