forked from stevenmills/bootstrapvalidator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathidentical.js
31 lines (29 loc) · 1.04 KB
/
identical.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
(function($) {
$.fn.bootstrapValidator.validators.identical = {
/**
* Check if input value equals to value of particular one
*
* @param {BootstrapValidator} validator The validator plugin instance
* @param {jQuery} $field Field element
* @param {Object} options Consists of the following key:
* - field: The name of field that will be used to compare with current one
* @returns {Boolean}
*/
validate: function(validator, $field, options) {
var value = $field.val();
if (value == '') {
return true;
}
var compareWith = validator.getFieldElements(options.field);
if (compareWith == null) {
return true;
}
if (value == compareWith.val()) {
validator.updateStatus(compareWith, 'identical', validator.STATUS_VALID);
return true;
} else {
return false;
}
}
};
}(window.jQuery));