Commit 5e9c8cb7 by Qiang Xue

Fixes issue #446: automatically scroll to first error.

parent c8df8e2a
......@@ -135,12 +135,16 @@
data.submitting = true;
if (!data.settings.beforeSubmit || data.settings.beforeSubmit($form)) {
validate($form, function (messages) {
var hasError = false;
var errors = [];
$.each(data.attributes, function () {
hasError = updateInput($form, this, messages) || hasError;
if (updateInput($form, this, messages)) {
errors.push(this.input);
}
});
updateSummary($form, messages);
if (!hasError) {
if (errors.length) {
$(window).scrollTop($form.find(errors.join(',')).first().offset().top);
} else {
data.validated = true;
var $button = data.submitObject || $form.find(':submit:first');
// TODO: if the submission is caused by "change" event, it will not work
......
Markdown is supported
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