|
@@ -270,6 +270,11 @@
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Init field element
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param {jQuery} $field The field element
|
|
|
|
|
+ */
|
|
|
_initFieldElement: function($field) {
|
|
_initFieldElement: function($field) {
|
|
|
var that = this,
|
|
var that = this,
|
|
|
field = $field.attr('name') || $field.attr('data-bv-field'),
|
|
field = $field.attr('name') || $field.attr('data-bv-field'),
|
|
@@ -486,6 +491,39 @@
|
|
|
}
|
|
}
|
|
|
},
|
|
},
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * Called after validating a field element
|
|
|
|
|
+ *
|
|
|
|
|
+ * @param {jQuery} $field The field element
|
|
|
|
|
+ */
|
|
|
|
|
+ _onValidateFieldCompleted: function($field) {
|
|
|
|
|
+ var field = $field.attr('data-bv-field'),
|
|
|
|
|
+ validators = this.options.fields[field].validators,
|
|
|
|
|
+ counter = {},
|
|
|
|
|
+ numValidators = 0;
|
|
|
|
|
+
|
|
|
|
|
+ counter[this.STATUS_NOT_VALIDATED] = 0;
|
|
|
|
|
+ counter[this.STATUS_VALIDATING] = 0;
|
|
|
|
|
+ counter[this.STATUS_INVALID] = 0;
|
|
|
|
|
+ counter[this.STATUS_VALID] = 0;
|
|
|
|
|
+
|
|
|
|
|
+ for (var validatorName in validators) {
|
|
|
|
|
+ numValidators++;
|
|
|
|
|
+ var result = $field.data('bv.result.' + validatorName);
|
|
|
|
|
+ if (result) {
|
|
|
|
|
+ counter[result]++;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (counter[this.STATUS_VALID] == numValidators) {
|
|
|
|
|
+ this.$form.trigger($.Event('success.field.bv'), [field, $field]);
|
|
|
|
|
+ }
|
|
|
|
|
+ // If all validators are completed and there is at least one validator which doesn't pass
|
|
|
|
|
+ else if (counter[this.STATUS_NOT_VALIDATED] == 0 && counter[this.STATUS_VALIDATING] == 0 && counter[this.STATUS_INVALID] > 0) {
|
|
|
|
|
+ this.$form.trigger($.Event('error.field.bv'), [field, $field]);
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+
|
|
|
// --- Public methods ---
|
|
// --- Public methods ---
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -587,6 +625,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) {
|
|
|
|
|
+ this._onValidateFieldCompleted($field);
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -672,6 +711,7 @@
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Show/hide error elements and feedback icons
|
|
// Show/hide error elements and feedback icons
|
|
|
|
|
+ validatorName ? $errors.filter('.help-block[data-bv-validator="' + validatorName + '"]').attr('data-bv-result', status) : $errors.attr('data-bv-result', status);
|
|
|
switch (status) {
|
|
switch (status) {
|
|
|
case this.STATUS_VALIDATING:
|
|
case this.STATUS_VALIDATING:
|
|
|
this.disableSubmitButtons(true);
|
|
this.disableSubmitButtons(true);
|
|
@@ -702,10 +742,10 @@
|
|
|
validatorName ? $errors.filter('[data-bv-validator="' + validatorName + '"]').hide() : $errors.hide();
|
|
validatorName ? $errors.filter('[data-bv-validator="' + validatorName + '"]').hide() : $errors.hide();
|
|
|
|
|
|
|
|
// If the field is valid (passes all validators)
|
|
// If the field is valid (passes all validators)
|
|
|
- var validField = ($errors.filter(function() {
|
|
|
|
|
- var display = $(this).css('display'), v = $(this).attr('data-bv-validator');
|
|
|
|
|
- return ('block' == display) || ($field.data('bv.result.' + v) != that.STATUS_VALID);
|
|
|
|
|
- }).length == 0);
|
|
|
|
|
|
|
+ var validField = $errors.filter(function() {
|
|
|
|
|
+ var v = $(this).attr('data-bv-validator');
|
|
|
|
|
+ return $field.data('bv.result.' + v) != that.STATUS_VALID;
|
|
|
|
|
+ }).length == 0;
|
|
|
this.disableSubmitButtons(validField ? false : true);
|
|
this.disableSubmitButtons(validField ? false : true);
|
|
|
if ($icon) {
|
|
if ($icon) {
|
|
|
$icon
|
|
$icon
|
|
@@ -744,6 +784,8 @@
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ this._onValidateFieldCompleted($field);
|
|
|
|
|
+
|
|
|
return this;
|
|
return this;
|
|
|
},
|
|
},
|
|
|
|
|
|