|
|
@@ -236,17 +236,6 @@
|
|
|
$field.attr('data-bv-field', field);
|
|
|
options.fields[field] = $.extend({}, opts, options.fields[field]);
|
|
|
}
|
|
|
- })
|
|
|
- .end()
|
|
|
- // Create hidden inputs to send the submit buttons
|
|
|
- .find(this.options.submitButtons)
|
|
|
- .each(function() {
|
|
|
- $('<input/>')
|
|
|
- .attr('type', 'hidden')
|
|
|
- .attr('data-bv-submit-hidden', '')
|
|
|
- .attr('name', $(this).attr('name'))
|
|
|
- .val($(this).val())
|
|
|
- .appendTo(that.$form);
|
|
|
});
|
|
|
|
|
|
this.options = $.extend(true, this.options, options);
|
|
|
@@ -680,14 +669,20 @@
|
|
|
$field.data('bv.result.' + validatorName, this.STATUS_VALIDATING);
|
|
|
validateResult = $.fn.bootstrapValidator.validators[validatorName].validate(this, $field, validators[validatorName]);
|
|
|
|
|
|
+ // validateResult can be a $.Deferred object ...
|
|
|
if ('object' == typeof validateResult) {
|
|
|
updateAll ? this.updateStatus(field, this.STATUS_VALIDATING, validatorName)
|
|
|
: this.updateElementStatus($field, this.STATUS_VALIDATING, validatorName);
|
|
|
$field.data('bv.dfs.' + validatorName, validateResult);
|
|
|
|
|
|
- validateResult.done(function($f, v, isValid) {
|
|
|
+ validateResult.done(function($f, v, isValid, message) {
|
|
|
// v is validator name
|
|
|
$f.removeData('bv.dfs.' + v);
|
|
|
+ if (message) {
|
|
|
+ // Update the error message
|
|
|
+ $field.data('bv.messages').find('.help-block[data-bv-validator="' + v + '"][data-bv-for="' + $f.attr('data-bv-field') + '"]').html(message);
|
|
|
+ }
|
|
|
+
|
|
|
updateAll ? that.updateStatus($f.attr('data-bv-field'), isValid ? that.STATUS_VALID : that.STATUS_INVALID, v)
|
|
|
: that.updateElementStatus($f, isValid ? that.STATUS_VALID : that.STATUS_INVALID, v);
|
|
|
|
|
|
@@ -696,7 +691,9 @@
|
|
|
that._submit();
|
|
|
}
|
|
|
});
|
|
|
- } else if ('boolean' == typeof validateResult) {
|
|
|
+ }
|
|
|
+ // ... or a boolean value
|
|
|
+ else if ('boolean' == typeof validateResult) {
|
|
|
updateAll ? this.updateStatus(field, validateResult ? this.STATUS_VALID : this.STATUS_INVALID, validatorName)
|
|
|
: this.updateElementStatus($field, validateResult ? this.STATUS_VALID : this.STATUS_INVALID, validatorName);
|
|
|
}
|
|
|
@@ -923,6 +920,16 @@
|
|
|
* It might be used when you want to submit the form right inside the submitHandler()
|
|
|
*/
|
|
|
defaultSubmit: function() {
|
|
|
+ if (this.$submitButton) {
|
|
|
+ // Create hidden input to send the submit buttons
|
|
|
+ $('<input/>')
|
|
|
+ .attr('type', 'hidden')
|
|
|
+ .attr('data-bv-submit-hidden', '')
|
|
|
+ .attr('name', this.$submitButton.attr('name'))
|
|
|
+ .val(this.$submitButton.val())
|
|
|
+ .appendTo(this.$form);
|
|
|
+ }
|
|
|
+ // Submit form
|
|
|
this.$form.off('submit.bv').submit();
|
|
|
},
|
|
|
|
|
|
@@ -978,6 +985,7 @@
|
|
|
.get()
|
|
|
);
|
|
|
});
|
|
|
+
|
|
|
return messages;
|
|
|
},
|
|
|
|
|
|
@@ -1348,8 +1356,9 @@
|
|
|
validate: function(validator, $field, options) {
|
|
|
var value = $field.val();
|
|
|
if (options.callback && 'function' == typeof options.callback) {
|
|
|
- var dfd = new $.Deferred();
|
|
|
- dfd.resolve($field, 'callback', options.callback.call(this, value, validator));
|
|
|
+ var dfd = new $.Deferred(),
|
|
|
+ response = options.callback.call(this, value, validator);
|
|
|
+ dfd.resolve($field, 'callback', 'boolean' == typeof response ? response : response.valid, 'object' == typeof response && response.message ? response.message : null);
|
|
|
return dfd;
|
|
|
}
|
|
|
return true;
|
|
|
@@ -3566,7 +3575,7 @@
|
|
|
data: data
|
|
|
});
|
|
|
xhr.then(function(response) {
|
|
|
- dfd.resolve($field, 'remote', response.valid === true || response.valid === 'true');
|
|
|
+ dfd.resolve($field, 'remote', response.valid === true || response.valid === 'true', response.message ? response.message : null);
|
|
|
});
|
|
|
|
|
|
dfd.fail(function() {
|