I use useForm and I want to scroll a user to the first error if it happens. Now, I set id for each div wrapper like so:
<div id="agency_section" class="input-wrapper">
<div v-if="form.errors.agency" class="rel">
<div class="error"><b></b>{{ form.errors.agency }}</div>
</div>
<input v-model="form.agency" required type="text">
</div>
and onError perform the next scrolling:
onError: (result) => {
window.scroll({
top: document.getElementById(Object.keys(result)[0] + '_section').getBoundingClientRect().top + window.scrollY - 30,
behavior: "smooth"
});
},
but I don't want to set id to each wrapper. I believe there's some solution in Inertia or Vue. Could someone help me with this fin-tune, please?