-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Animated scroll to first error after form validate #7259
Comments
Not sure about your validation options, we used $('#form-id').on('afterValidate', function (event, messages) {
if(typeof $('.has-error').first().offset() !== 'undefined') {
$('html, body').animate({
scrollTop: $('.has-error').first().offset().top
}, 1000);
}
}); |
Yes, but that doesn't work properly. The hardcoded jump causes the page to jump to the top, then in the next tick of jquery's animation it jumps back down and then it animates up. That initial jump is the problem. |
Added errorAttributes to afterValidate event, and moved default scrolling behavior to afterValidate event handler. Fixes yiisoft#7259
Line 504 of yii.activeform.js has an error and scrolling doesn't work:
|
Thanks. I fixed it in my PR but the bug is in the original code. |
The default code also doesn't take into account any fixed headers, so you'll end up with inputs partially under the header. The basic template's contact form exhibits this problem. |
Added errorAttributes to afterValidate event, and moved default scrolling behavior to afterValidate event handler. Fixes yiisoft#7259
Added errorAttributes to afterValidate event, and moved default scrolling behavior to afterValidate event handler. Fixes yiisoft#7259
updateInputs scrolls to the first visible input that has an error.
I'd like to do an animated scroll, but I can't because of this.
The text was updated successfully, but these errors were encountered: