# Any way to access state's element?

**URL:** <https://community.weweb.io/t/any-way-to-access-states-element/5475>\
**Category:** Developer corner\
**Created:** [November 19, 2023, 9:11pm UTC](https://community.weweb.io/t/any-way-to-access-states-element/5475 "2023-11-19T21:11:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Broberto](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/broberto/32/5918_2.png) [@Broberto](https://community.weweb.io/u/Broberto)\
**Post date:** [November 19, 2023, 9:11pm UTC](https://community.weweb.io/t/any-way-to-access-states-element/5475/1 "2023-11-19T21:11:30Z")

</div>

I use regex in my states to set errors if the fields are not filled/filled with wrong data. I have a form that is long and overflows. What I’d like to do, is check for validity and if invalid do something like `this.scrollIntoView()` with the this being the target of the state. Is this even possible? How do states work? Is it just a dynamic class?

---

<div class="post-metadata">

**Author:** ![Alexis](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/alexis/32/13248_2.png) [@Alexis](https://community.weweb.io/u/Alexis)\
**Post date:** [November 30, 2023, 4:41pm UTC](https://community.weweb.io/t/any-way-to-access-states-element/5475/2 "2023-11-30T16:41:13Z")

</div>

I dont think it’s possible from nocode/lowcode. You can from coded components.

But maybe we could expose it the same way we expose elements position, by adding a watch state on settings and expose elements states globally. Opinion @aurelie ?

For now you will probably have to do it differently. You can apply a native class on your fields and scroll to the first element found with the error class for exemple.

![Capture d’écran 2023-11-30 à 17.40.58](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/2X/8/891bc46d596b04bae1e05b45c48e13fc3bb9abd3.png)

---

<div class="post-metadata">

**Author:** ![Broberto](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/broberto/32/5918_2.png) [@Broberto](https://community.weweb.io/u/Broberto)\
**Post date:** [November 30, 2023, 4:46pm UTC](https://community.weweb.io/t/any-way-to-access-states-element/5475/3 "2023-11-30T16:46:45Z")

</div>

I actually kept the HTML validation, and on invalid, I trigger this.scrollIntoView(); So that works for now 🙂

---

<div class="post-metadata">

**Author:** ![aurelie](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/aurelie/32/13249_2.png) [@aurelie](https://community.weweb.io/u/aurelie)\
**Post date:** [November 30, 2023, 5:24pm UTC](https://community.weweb.io/t/any-way-to-access-states-element/5475/4 "2023-11-30T17:24:08Z")

</div>

States are an internal data that we do not expose at the moment.  
At the moment, the best way to do it will be to have an id/class on the element, and use js to scrollInto.

When we will rework the components actions, maybe we can add a way to get the HTML element instance, or just add a “ScrollIntoView” actions

---

<div class="post-metadata">

**Author:** ![Broberto](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/broberto/32/5918_2.png) [@Broberto](https://community.weweb.io/u/Broberto)\
**Post date:** [November 30, 2023, 6:35pm UTC](https://community.weweb.io/t/any-way-to-access-states-element/5475/5 "2023-11-30T18:35:21Z")

</div>

Actually, it would be enough to be able to have the HTML element reference. But thanks for the reply 🙂
