Commit 09ac0f52 authored by Rafael Ostertag's avatar Rafael Ostertag
Browse files

Form.js: When boostrap-validator is available use it to validate forms,...

Form.js: When boostrap-validator is available use it to validate forms, instead of blindly using .checkValidity() on. Allows to detect errors recognized only by bootstrap-validator.
parent 086f470b
......@@ -118,12 +118,20 @@ var QfqNS = QfqNS || {};
*/
n.Form.prototype.validate = function () {
this.eventEmitter.emitEvent('form.validation.before', n.EventEmitter.makePayload(this, null));
var isValid;
var form = document.forms[this.formId];
var $form = $(form);
if ($form.data('bs.validator')) {
$form.validator('validate');
isValid = !$form.data('bs.validator').hasErrors();
} else {
isValid = form.checkValidity();
}
var result = document.forms[this.formId].checkValidity();
this.eventEmitter.emitEvent('form.validation.after', n.EventEmitter.makePayload(this, {validationResult: result}));
this.eventEmitter.emitEvent('form.validation.after', n.EventEmitter.makePayload(this, {validationResult: isValid}));
return result;
return isValid;
};
/**
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment