Created
November 7, 2015 01:12
-
-
Save shinespark/45a6d2592387724f1078 to your computer and use it in GitHub Desktop.
check duplicate for jquery validation plugin
This file contains 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
/* | |
* 指定: {notDuplicate: '.class-name'} | |
* なお、指定された要素が空, 未選択に戻された際はチェックokとする | |
*/ | |
jQuery.validator.addMethod('notDuplicate', function( value, element, param ) { | |
if ($(element).val() === '') { | |
return true; | |
} | |
var that = this; | |
var bool = true; | |
$(param).each(function() { | |
if (element === $(this).get(0)) { // 自身との同一チェックは行わない | |
return true; | |
} | |
bool = bool && !$.validator.methods.equalTo.call(that, value, element, this); | |
}); | |
return this.optional(element) || bool; | |
}, '異なる項目をご選択ください' ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment