Browse Source

Fixes issue #446: automatically scroll to first error.

tags/2.0.0-beta
Qiang Xue 12 years ago
parent
commit
5e9c8cb7c4
  1. 10
      framework/yii/assets/yii.activeForm.js

10
framework/yii/assets/yii.activeForm.js

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

Loading…
Cancel
Save