Skip to content

Core: Add greaterThan and lessThan methods. #2061

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

Merged

Conversation

RobJohnston
Copy link
Contributor

Fixes #2030.

Tests are limited to integers, but I think that other data types would work too.

@Arkni
Copy link
Member

Arkni commented Sep 11, 2017

Thanks for the PR.

Looks good to me.

Can you also unbind the event and remove the class name in validator#destroy() as done for equalTo method?

jquery-validation/src/core.js

Lines 1121 to 1123 in 539fa4d

.find( ".validate-equalTo-blur" )
.off( ".validate-equalTo" )
.removeClass( "validate-equalTo-blur" );

As for testing the above request, you can do the same as the PR #1709

@RobJohnston
Copy link
Contributor Author

@Arkni So did I get it, or do I need to do some more studying of this repo?

@staabm staabm requested a review from Arkni September 16, 2017 08:49
$.validator.addMethod( "greaterThan", function( value, element, param ) {
var target = $( param );

if ( this.settings.onfocusout && target.not( ".validate-greaterThan-blur" ).length ) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need this focus handling?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My motivation was to follow the pattern of the equalTo method, and this was introduced there two years ago in Core: Bind the blur event just once in equalTo rule .

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a clarification, the focus handling was added +5 years ago in this commit aca144b#diff-a692042a498ec7e201f38855d169e7b1R1163. The only thing that was added in the commit linked by @RobJohnston is binding the blur event one time.

Copy link
Member

@Arkni Arkni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@staabm
Copy link
Member

staabm commented Sep 19, 2017

@RobJohnston do you have a actual use case for this newly added methods?

I am fine with adding them in case there is a need for it.
Only thing I dont like is the few lines added in core.js, but ok in case of a use case..

@RobJohnston
Copy link
Contributor Author

Yes I do. I have an application where people must record the inventory that they use, and each item in inventory has a serial number. At the end of the day, they have a range of consumed inventory, and this validation would ensure that the start serial number is less than the end serial number (or end is greater than start). If they only consumed one piece of inventory, then the end serial number has to be greater than or equal to the start serial number.

I thought it would be an easy PR to accept due to the previous discussion in #458 (comment).

@staabm staabm merged commit 38cb9b9 into jquery-validation:master Sep 19, 2017
@staabm
Copy link
Member

staabm commented Sep 19, 2017

Thx for your detailed feedback

@staabm staabm mentioned this pull request Sep 19, 2017
2 tasks
@RobJohnston RobJohnston deleted the 2030-greaterThan-lessThan branch September 20, 2017 00:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants