Skip to content
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

Closed
nkovacs opened this issue Feb 12, 2015 · 5 comments
Closed

Animated scroll to first error after form validate #7259

nkovacs opened this issue Feb 12, 2015 · 5 comments
Assignees
Milestone

Comments

@nkovacs
Copy link
Contributor

nkovacs commented Feb 12, 2015

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.

@samdark samdark added this to the 2.0.x milestone Feb 13, 2015
@disem
Copy link
Contributor

disem commented Feb 25, 2015

Not sure about your validation options, we used afterValidate event to achieve this behavior with ajax validation, something like:

$('#form-id').on('afterValidate', function (event, messages) {
    if(typeof $('.has-error').first().offset() !== 'undefined') {
        $('html, body').animate({
            scrollTop: $('.has-error').first().offset().top
        }, 1000);
    }
});

@nkovacs
Copy link
Contributor Author

nkovacs commented Apr 17, 2015

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.

nkovacs added a commit to nkovacs/yii2 that referenced this issue Apr 17, 2015
Added errorAttributes to afterValidate event, and moved default scrolling
behavior to afterValidate event handler.

Fixes yiisoft#7259
@TimNZ
Copy link

TimNZ commented Jun 1, 2015

Line 504 of yii.activeform.js has an error and scrolling doesn't work:

$(window).height => $(window).height()

                if (top < wtop || top > wtop + $(window).height) {
                    $(window).scrollTop(top);
                }

@nkovacs
Copy link
Contributor Author

nkovacs commented Jun 1, 2015

Thanks. I fixed it in my PR but the bug is in the original code.

@nkovacs
Copy link
Contributor Author

nkovacs commented Jun 4, 2015

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.

@samdark samdark modified the milestones: 2.0.5, 2.0.x Jun 4, 2015
@samdark samdark modified the milestones: 2.0.7, 2.0.6 Jul 27, 2015
nkovacs added a commit to nkovacs/yii2 that referenced this issue Jul 29, 2015
Added errorAttributes to afterValidate event, and moved default scrolling
behavior to afterValidate event handler.

Fixes yiisoft#7259
nkovacs added a commit to nkovacs/yii2 that referenced this issue Jul 29, 2015
Added errorAttributes to afterValidate event, and moved default scrolling
behavior to afterValidate event handler.

Fixes yiisoft#7259
@samdark samdark closed this as completed in 2577a59 Aug 2, 2015
@samdark samdark modified the milestones: 2.0.6, 2.0.7 Aug 2, 2015
@samdark samdark self-assigned this Aug 2, 2015
samdark added a commit that referenced this issue Aug 2, 2015
samdark added a commit that referenced this issue Aug 2, 2015
samdark added a commit that referenced this issue Aug 2, 2015
samdark added a commit that referenced this issue Aug 2, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants