-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
staabm
merged 5 commits into
jquery-validation:master
from
RobJohnston:2030-greaterThan-lessThan
Sep 19, 2017
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
2988a6c
Additional: Add greaterThan and lessThan methods.
RobJohnston 0a706db
Tests: Add tests for integers.
RobJohnston 18c3143
Core: Unbind the event and remove the class name.
RobJohnston 6b6e619
Test: Test binding of blur event.
RobJohnston bc6f79a
Test: Test binding of blur event.
RobJohnston File filter
Filter by extension
Conversations
Failed to
8000
load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
$.validator.addMethod( "greaterThan", function( value, element, param ) { | ||
var target = $( param ); | ||
|
||
if ( this.settings.onfocusout && target.not( ".validate-greaterThan-blur" ).length ) { | ||
target.addClass( "validate-greaterThan-blur" ).on( "blur.validate-greaterThan", function() { | ||
$( element ).valid(); | ||
} ); | ||
} | ||
|
||
return value > target.val(); | ||
}, "Please enter a greater value." ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
$.validator.addMethod( "greaterThanEqual", function( value, element, param ) { | ||
var target = $( param ); | ||
|
||
if ( this.settings.onfocusout && target.not( ".validate-greaterThanEqual-blur" ).length ) { | ||
target.addClass( "validate-greaterThanEqual-blur" ).on( "blur.validate-greaterThanEqual", function() { | ||
$( element ).valid(); | ||
} ); | ||
} | ||
|
||
return value >= target.val(); | ||
}, "Please enter a greater value." ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
$.validator.addMethod( "lessThan", function( value, element, param ) { | ||
var target = $( param ); | ||
|
||
if ( this.settings.onfocusout && target.not( ".validate-lessThan-blur" ).length ) { | ||
target.addClass( "validate-lessThan-blur" ).on( "blur.validate-lessThan", function() { | ||
$( element ).valid(); | ||
} ); | ||
} | ||
|
||
return value < target.val(); | ||
}, "Please enter a lesser value." ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
$.validator.addMethod( "lessThanEqual", function( value, element, param ) { | ||
var target = $( param ); | ||
|
||
if ( this.settings.onfocusout && target.not( ".validate-lessThanEqual-blur" ).length ) { | ||
target.addClass( "validate-lessThanEqual-blur" ).on( "blur.validate-lessThanEqual", function() { | ||
$( element ).valid(); | ||
} ); | ||
} | ||
|
||
return value <= target.val(); | ||
}, "Please enter a lesser value." ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 inequalTo
rule .There was a problem hiding this comment.
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.