Vuelidate: Scroll to the first error

Created on 12 Mar 2018  路  3Comments  路  Source: vuelidate/vuelidate

is it possible to scroll to the first error field ?

Most helpful comment

I got this to work, but a non-native javascript with scroll animation would be better.
In your template:

<input :class="{ 'input--error': $v.name.$error}" >

In your methods:

```
this.$nextTick(() => {
let domRect = document.querySelector('.input--error').getBoundingClientRect();
window.scrollTo(
domRect.left + document.documentElement.scrollLeft,
domRect.top + document.documentElement.scrollTop
);
})

All 3 comments

Yes. You have to implement scrolling to the node on your own. Vuelidate already makes it pretty easy to detect where error occured by inspecting $v.

I got this to work, but a non-native javascript with scroll animation would be better.
In your template:

<input :class="{ 'input--error': $v.name.$error}" >

In your methods:

```
this.$nextTick(() => {
let domRect = document.querySelector('.input--error').getBoundingClientRect();
window.scrollTo(
domRect.left + document.documentElement.scrollLeft,
domRect.top + document.documentElement.scrollTop
);
})

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hackuun picture hackuun  路  4Comments

jess8bit picture jess8bit  路  3Comments

mrcha90 picture mrcha90  路  3Comments

thibremy picture thibremy  路  4Comments

andrefigueira picture andrefigueira  路  3Comments