Skip to content

Loading…

New method: notEqualTo #1020

Closed
wants to merge 5 commits into from

2 participants

@robotdan

New method ‘notEqualTo’ that delegates to the notEqual method and
returns the inverted value.

robotdan added some commits
@robotdan robotdan New method: notEqualTo
New method ‘notEqualTo’ that delegates to the notEqual method and
returns the inverted value.
c2a81dc
@robotdan robotdan White space 4f36be0
@jzaefferer jzaefferer commented on an outdated diff
src/additional/notEqualTo.js
@@ -0,0 +1,3 @@
+jQuery.validator.addMethod( "notEqualTo", function( value, element, param ) {
+ return !$.validator.methods.equalTo.call( this, value, element, param );
@jzaefferer Owner

Shouldn't this also respect the optional state like other methods do?

@robotdan
robotdan added a note

I had assumed I'd get that for free since I'm delegating to the existing method equalTo? I'll verify that and add if not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@jzaefferer jzaefferer commented on an outdated diff
test/methods.js
@@ -319,6 +319,15 @@ test("equalTo", function() {
ok( method.call( v, "T", e[1], "#text2" ), "Another one" );
});
+test("notEqualTo", function() {
+ var v = jQuery("#form").validate(),
+ method = $.validator.methods.notEqualTo,
+ e = $("#text1, #text2");
+
+ ok( !method.call( v, "Test", e[0], "#text1" ), "Text input" );
+ ok( !method.call( v, "T", e[1], "#text2" ), "Another one" );
@jzaefferer Owner

There should be at least on positive assertion.

@robotdan
robotdan added a note

Thanks, I'll add that, and I'll beef this up a bit more to test the optional states as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
@jzaefferer
Owner

There are no notifications for new commits, so I never noticed that you added one until now. Trying to merge this now causes merge conflicts - could you rebase this PR and squash it into one commit? Thanks.

@robotdan

yes.

@jzaefferer jzaefferer added a commit that closed this pull request
@robotdan robotdan Additionals: Add notEqualTo method
New method ‘notEqualTo’ that delegates to the equalTo method and
returns the inverted value.

Closes #1020
c4b891e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 22, 2014
  1. @robotdan

    New method: notEqualTo

    robotdan committed
    New method ‘notEqualTo’ that delegates to the notEqual method and
    returns the inverted value.
  2. @robotdan

    White space

    robotdan committed
Commits on Mar 8, 2014
  1. @robotdan
Commits on Jul 3, 2014
  1. @robotdan

    Merge remote-tracking branch 'upstream/master'

    robotdan committed
    Conflicts:
    	test/index.html
  2. @robotdan

    update gitignore

    robotdan committed
Showing with 18 additions and 1 deletion.
  1. +2 −1 .gitignore
  2. +3 −0 src/additional/notEqualTo.js
  3. +13 −0 test/methods.js
View
3 .gitignore
@@ -6,4 +6,5 @@ docs
*.diff
*.patch
.DS_Store
-node_modules
+node_modules
+.idea/
View
3 src/additional/notEqualTo.js
@@ -0,0 +1,3 @@
+jQuery.validator.addMethod( "notEqualTo", function( value, element, param ) {
+ return this.optional(element) || !$.validator.methods.equalTo.call( this, value, element, param );
+}, "Please enter a different value, values must not be the same." );
View
13 test/methods.js
@@ -1254,4 +1254,17 @@ test("stateUS", function() {
ok(!method( "mp", { caseSensitive: false, includeTerritories: false } ), "US territories not allowed" );
});
+test("notEqualTo", function() {
+
+ var v = $( "#notEqualTo" ).validate(),
+ method = $.validator.methods.notEqualTo,
+ e = $( "#email1, #email2, #email3" ),
+ id = [ "#email1Backup", "#email2Backup", "#email3Backup" ];
+
+ ok ( method.call( v, e[0].value, e[0], id[0] ), "Backup email is different than the primary." );
+ ok (!method.call( v, e[1].value, e[1], id[1] ), "Backup email is the same as the primary." );
+ ok ( method.call( v, e[2].value, e[2], id[2] ), "Optional, empty values won't be compared." );
+
+});
+
})(jQuery);
Something went wrong with that request. Please try again.