Min and max validation now use type attribute to determine behavior #355
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When used as HTML5 attributes, min and max were comparing as strings. So an element of
<input min="10" data-bind="value:myNumber">
would validate successfully for a value of 5, because the string "5" is greater than the string "10". This was understandably causing some problems.This update changes the min and max validators so that they pay attention to the type attribute. For example, the element
<input type="month" min="2010-03" data-bind="value:myMonth">
will use appropriate logic to ensure that the entered date is entered as a month and is March 2010 or later. And an element of<input type="number" min="10" data-bind="value:myNumber">
will fail validation if a value of 5 is entered.Tests and Documentation updates included.
This was originally in PR #324, but I decided to create a new PR after the Knockout-Validation folder restructuring so that this could be a single, clean commit.
Thanks to @stevegreatrex for help in reviewing this feature.