B4J Question [BANanoVuetifyAD3] how set focus to specific VTextField

Star-Dust

Expert
Licensed User
Longtime User
 
Upvote 0

Mashiane

Expert
Licensed User
Longtime User
Because would want to focus on any component, this has been to be at page level. You need the name of the component that you want to focus to.

You can focus on an element when the page is shown or via an event e.g. a click.

To focus on an element, when the page is shown, use the "AutoFocus" property of that component and check it in the property bag.

To focus on an element when an event happens. This is what needs to happen

Step 1: Get access to the page references.

1. Each page in your app, will always sit on top of the router-view. Each element on your page has a reference i.e. id. Internally VueJS needs to store these in a "refs" table. These "refs" change each time you navigate to another page, so to get the latest reference to them. Execute.

B4X:
page.RefreshActiveRefs(vuetify)

Step 2: Set the focus to the element

Then, you can focus to an element using its "ref", by running

B4X:
page.SetFocus("mycomponentname")

So the final code is

B4X:
page.RefreshActiveRefs(vuetify)
page.SetFocus("mycomponentname")

Happy BVAD3 Coding!
 
Upvote 0
Top