Closed geoidesic closed 2 years ago
Hi @geoidesic! 👋
It looks like you provided an invalid or unsupported reproduction URL. Do not use any service other than Codepen, jsFiddle, Codesandbox, and GitHub. Make sure the URL you provided is correct and reachable. You can test it by visiting it in a private tab, another device, etc. Please edit your original post above and provide a valid reproduction URL as explained.
Without a proper reproduction, your issue will have to get closed.
Thank you for your collaboration. 👏
This is by design, because auto scrolling on focus can cause a lot of problems in containers that are animated.
But you can listen for the @validation-error
event - you'll get a ref to the component and you can do a scrollIntoView
on it.
The reason it scrolls in ~IE~ Safari is because it does not implement the preventScroll
for focus
Thanks for the reply @pdanpdan. I tried @validation-error
but I get an error:
TypeError: el.scrollIntoView is not a function"
Here's my code:
<template>
...
@validation-error="validationError"
...
<script>
...
methods: {
validationError(el) {
el.scrollIntoView();
...
nvm... figured it out:
el.$el.scrollIntoView();
Although with that in place the validation no longer works correctly. On first submit, the validation passes (even though it failed). This code is inside a q-stepper
and with the scrollIntoView
instead of stopping the submit, it progresses to the next step in the form wizard (i.e. the stepper). This happens because the @validation-error
event does not trigger in this case. However, if I then go back to the first step and submit again, then it works. Note that this behaviour only occurs if I have the greedy
prop enabled on the q-form
, without that it works as expected.
I have created a new sandbox to illustrate the issue: https://codesandbox.io/s/quasar-form-scroll-on-validation-forked-5bosgh?file=/src/components/StandardForm.vue . This is slightly different from my use-case in that it is not encapsulated in a q-stepper
but you can still note that the event does not trigger as the alert never occurs.
You have a problem with the rules - they are generated by a function and you will get a new set of rules every time something re-renders.
I don't understand?
Not sure how that relates to the problem, nor why greedy
would expose that, nor how to fix it.
Oh wait, I see you provided an updated example. My bad. Let me look at that...
I see now. Understood. Thanks!
What happened?
Here's the example of the problem: https://6vjl2t.sse.codesandbox.io/
The issue is that when validation fails (on the
name
field e.g.) and the window is short (i.e. scrollbar appears) and one clicks Submit, the window does not scroll to the invalid field.It does scroll on Safari, but it does not on Chrome (tested on Mac and Windows), nor on Firefox (tested on Mac).
What did you expect to happen?
It should scroll on all browsers.
Reproduction URL
https://codesandbox.io/s/quasar-form-scroll-on-validation-6vjl2t
How to reproduce?
Flavour
Quasar CLI (@quasar/cli | @quasar/app)
Areas
Components (quasar), SPA Mode
Platforms/Browsers
Firefox, Chrome
Quasar info output
Relevant log output
No response
Additional context
No response