|
@@ -2,7 +2,7 @@
|
|
|
* BootstrapValidator (http://bootstrapvalidator.com)
|
|
* BootstrapValidator (http://bootstrapvalidator.com)
|
|
|
* The best jQuery plugin to validate form fields. Designed to use with Bootstrap 3
|
|
* The best jQuery plugin to validate form fields. Designed to use with Bootstrap 3
|
|
|
*
|
|
*
|
|
|
- * @version v0.5.0-dev, built on 2014-06-29 9:01:15 AM
|
|
|
|
|
|
|
+ * @version v0.5.0-dev, built on 2014-06-29 9:46:23 PM
|
|
|
* @author https://twitter.com/nghuuphuoc
|
|
* @author https://twitter.com/nghuuphuoc
|
|
|
* @copyright (c) 2013 - 2014 Nguyen Huu Phuoc
|
|
* @copyright (c) 2013 - 2014 Nguyen Huu Phuoc
|
|
|
* @license MIT
|
|
* @license MIT
|
|
@@ -593,6 +593,10 @@
|
|
|
counter[this.STATUS_VALID] = 0;
|
|
counter[this.STATUS_VALID] = 0;
|
|
|
|
|
|
|
|
for (var v in validators) {
|
|
for (var v in validators) {
|
|
|
|
|
+ if (validators[v].enabled === false) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
numValidators++;
|
|
numValidators++;
|
|
|
var result = $field.data('bv.result.' + v);
|
|
var result = $field.data('bv.result.' + v);
|
|
|
if (result) {
|
|
if (result) {
|
|
@@ -733,7 +737,7 @@
|
|
|
|
|
|
|
|
// Don't validate field if it is already done
|
|
// Don't validate field if it is already done
|
|
|
var result = $field.data('bv.result.' + validatorName);
|
|
var result = $field.data('bv.result.' + validatorName);
|
|
|
- if (result === this.STATUS_VALID || result === this.STATUS_INVALID) {
|
|
|
|
|
|
|
+ if (result === this.STATUS_VALID || result === this.STATUS_INVALID || validators[validatorName].enabled === false) {
|
|
|
this._onFieldValidated($field, validatorName);
|
|
this._onFieldValidated($field, validatorName);
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
@@ -995,6 +999,10 @@
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
for (validatorName in this.options.fields[field].validators) {
|
|
for (validatorName in this.options.fields[field].validators) {
|
|
|
|
|
+ if (this.options.fields[field].validators[validatorName].enabled === false) {
|
|
|
|
|
+ continue;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
status = $field.data('bv.result.' + validatorName);
|
|
status = $field.data('bv.result.' + validatorName);
|
|
|
if (status !== this.STATUS_VALID) {
|
|
if (status !== this.STATUS_VALID) {
|
|
|
return false;
|
|
return false;
|
|
@@ -1027,8 +1035,10 @@
|
|
|
if ($f.data('bv.messages')
|
|
if ($f.data('bv.messages')
|
|
|
.find('.help-block[data-bv-validator][data-bv-for="' + field + '"]')
|
|
.find('.help-block[data-bv-validator][data-bv-for="' + field + '"]')
|
|
|
.filter(function() {
|
|
.filter(function() {
|
|
|
- var v = $(this).attr('data-bv-validator');
|
|
|
|
|
- return ($f.data('bv.result.' + v) && $f.data('bv.result.' + v) !== that.STATUS_VALID);
|
|
|
|
|
|
|
+ var v = $(this).attr('data-bv-validator'),
|
|
|
|
|
+ f = $(this).attr('data-bv-for');
|
|
|
|
|
+ return (that.options.fields[f].validators[v].enabled !== false
|
|
|
|
|
+ && $f.data('bv.result.' + v) && $f.data('bv.result.' + v) !== that.STATUS_VALID);
|
|
|
})
|
|
})
|
|
|
.length !== 0)
|
|
.length !== 0)
|
|
|
{
|
|
{
|
|
@@ -1056,6 +1066,7 @@
|
|
|
.val(this.$submitButton.val())
|
|
.val(this.$submitButton.val())
|
|
|
.appendTo(this.$form);
|
|
.appendTo(this.$form);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
// Submit form
|
|
// Submit form
|
|
|
this.$form.off('submit.bv').submit();
|
|
this.$form.off('submit.bv').submit();
|
|
|
},
|
|
},
|
|
@@ -1119,7 +1130,9 @@
|
|
|
.data('bv.messages')
|
|
.data('bv.messages')
|
|
|
.find('.help-block[data-bv-for="' + $(this).attr('data-bv-field') + '"][data-bv-result="' + that.STATUS_INVALID + '"]' + filter)
|
|
.find('.help-block[data-bv-for="' + $(this).attr('data-bv-field') + '"][data-bv-result="' + that.STATUS_INVALID + '"]' + filter)
|
|
|
.map(function() {
|
|
.map(function() {
|
|
|
- return $(this).html();
|
|
|
|
|
|
|
+ var v = $(this).attr('data-bv-validator'),
|
|
|
|
|
+ f = $(this).attr('data-bv-for');
|
|
|
|
|
+ return (that.options.fields[f].validators[v].enabled === false) ? '' : $(this).html();
|
|
|
})
|
|
})
|
|
|
.get()
|
|
.get()
|
|
|
);
|
|
);
|
|
@@ -1307,12 +1320,26 @@
|
|
|
*
|
|
*
|
|
|
* @param {String} field The field name
|
|
* @param {String} field The field name
|
|
|
* @param {Boolean} enabled Enable/Disable field validators
|
|
* @param {Boolean} enabled Enable/Disable field validators
|
|
|
|
|
+ * @param {String} [validatorName] The validator name. If null, all validators will be enabled/disabled
|
|
|
* @returns {BootstrapValidator}
|
|
* @returns {BootstrapValidator}
|
|
|
*/
|
|
*/
|
|
|
- enableFieldValidators: function(field, enabled) {
|
|
|
|
|
- if (this.options.fields[field].enabled !== enabled) {
|
|
|
|
|
|
|
+ enableFieldValidators: function(field, enabled, validatorName) {
|
|
|
|
|
+ var validators = this.options.fields[field].validators;
|
|
|
|
|
+
|
|
|
|
|
+ // Enable/disable particular validator
|
|
|
|
|
+ if (validatorName
|
|
|
|
|
+ && validators
|
|
|
|
|
+ && validators[validatorName] && validators[validatorName].enabled !== enabled)
|
|
|
|
|
+ {
|
|
|
|
|
+ this.options.fields[field].validators[validatorName].enabled = enabled;
|
|
|
|
|
+ this.updateStatus(field, this.STATUS_NOT_VALIDATED, validatorName);
|
|
|
|
|
+ }
|
|
|
|
|
+ // Enable/disable all validators
|
|
|
|
|
+ else if (!validatorName && this.options.fields[field].enabled !== enabled) {
|
|
|
this.options.fields[field].enabled = enabled;
|
|
this.options.fields[field].enabled = enabled;
|
|
|
- this.updateStatus(field, this.STATUS_NOT_VALIDATED);
|
|
|
|
|
|
|
+ for (var v in validators) {
|
|
|
|
|
+ this.enableFieldValidators(field, enabled, v);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return this;
|
|
return this;
|