mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-19 16:01:57 +08:00
Fixes issue #446: automatically scroll to first error.
This commit is contained in:
@@ -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
|
||||||
|
|||||||
Reference in New Issue
Block a user