Version: 3.1.14
Bug Description
Bug is related to the commit netteForms: min/max/range can compare strings.
When a form control is used as an argument in the rule, then a numeric string is passed to the js validator and it's not parsed as float, so there is a wrong comparison made.
Example: '100' >= '2' is false in JavaScript.
Steps To Reproduce
$form = new \Nette\Forms\Form();
$form->addFloat('min_age', 'Min age')
->setDefaultValue(6);
$form->addFloat('max_age', 'Max age')
->setDefaultValue(100)
->addRule(\Nette\Forms\Form::Min, null, $form['min_age']);
$form->addSubmit('save', 'Save');
echo$form;
// on submit js error: Please enter a value greater than or equal to 6.Expected Behavior
Floats and integers should be compared as numbers, not as strings.
Possible Solution
min: function(elem,arg,val){if((/^-?[0-9]*\.?[0-9]+$/).test(arg)){val=parseFloat(val);}returnval>=arg;},max: function(elem,arg,val){if((/^-?[0-9]*\.?[0-9]+$/).test(arg)){val=parseFloat(val);}returnval<=arg;},
Version: 3.1.14
Bug Description
Bug is related to the commit netteForms: min/max/range can compare strings.
When a form control is used as an argument in the rule, then a numeric string is passed to the js validator and it's not parsed as float, so there is a wrong comparison made.
Example: '100' >= '2' is false in JavaScript.
Steps To Reproduce
Expected Behavior
Floats and integers should be compared as numbers, not as strings.
Possible Solution