# Aurelia-validation plugin auto scroll in large collections

**URL:** <https://discourse.aurelia.io/t/aurelia-validation-plugin-auto-scroll-in-large-collections/4053>\
**Category:** Framework Knowledge\
**Created:** [February 20, 2021, 2:44pm UTC](https://discourse.aurelia.io/t/aurelia-validation-plugin-auto-scroll-in-large-collections/4053 "2021-02-20T14:44:27Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bmarotta](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/bmarotta/32/1854_2.png) [@bmarotta](https://discourse.aurelia.io/u/bmarotta)\
**Post date:** [February 20, 2021, 2:44pm UTC](https://discourse.aurelia.io/t/aurelia-validation-plugin-auto-scroll-in-large-collections/4053/1 "2021-02-20T14:44:27Z")

</div>

Hi,

When using aurelia-validation plugin in large collections (many scroll pages on mobile), is there any out-of-the-box solution for scrolling to the validation error? Or do I have to implement it myself?

The only workaround I found for it was to add and id on each row and then call myself scrollIntoView for the affected element:

```
let invalid = result.results.filter(n => !n.valid);
let first = invalid[0];
if (first.object instanceof QuizDbEntry) {
  // Scroll to top
  Utility.safeScrollIntoView(document.getElementById('quiz-header-row'))
} else {
  let obj = first.object;
  let idx = this.quizEntry.questions.indexOf(obj);
  if (idx > -1) {
    Utility.safeScrollIntoView(document.getElementById('quiz-question-row-' + (idx + 1)));
  }
}
```

---

<div class="post-metadata">

**Author:** ![zewa666](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/zewa666/32/19_2.png) [@zewa666](https://discourse.aurelia.io/u/zewa666)\
**Post date:** [February 20, 2021, 4:15pm UTC](https://discourse.aurelia.io/t/aurelia-validation-plugin-auto-scroll-in-large-collections/4053/2 "2021-02-20T16:15:22Z")

</div>

You’d be best served with a [custom renderer](http://aurelia.io/docs/plugins/validation#custom-renderers) as there you’ll get access to the DOM element having an Error. In there you can easily add your scrolltologic. Make sure to handle the case for multiple errors by using a debounce or the likes

---

<div class="post-metadata">

**Author:** ![bmarotta](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/bmarotta/32/1854_2.png) [@bmarotta](https://discourse.aurelia.io/u/bmarotta)\
**Post date:** [February 20, 2021, 4:23pm UTC](https://discourse.aurelia.io/t/aurelia-validation-plugin-auto-scroll-in-large-collections/4053/3 "2021-02-20T16:23:47Z")

</div>

Hi @zewa666, thanks but it looks like with the custom renderer I’ll have to write a lot more code. Or can I call the default behavior from the custom renderer to display the error message and then do the scroll?

Cheers

---

<div class="post-metadata">

**Author:** ![zewa666](https://yyz1.discourse-cdn.com/flex027/user_avatar/discourse.aurelia.io/zewa666/32/19_2.png) [@zewa666](https://discourse.aurelia.io/u/zewa666)\
**Post date:** [February 20, 2021, 4:42pm UTC](https://discourse.aurelia.io/t/aurelia-validation-plugin-auto-scroll-in-large-collections/4053/4 "2021-02-20T16:42:24Z")

</div>

Well In usually always have a custom renderer in place to adjust rendering. Honestly no idea whether you could call the original implementations methods.

Alternatively the `subscribe(callback: (event: ValidateEvent) => void)` Event might be another approach being called after a validation or reset occurs. Dunno if you can obtain the target element using that though.
