Skip to content
Discussion options

You must be logged in to vote

Hi @Anindya088,

This one is a bit tricky, because in case of ui.input, getElement doesn't immediately give you the HTML element to call focus() on. But luckily there's a workaround based on a Vue reference "qRef" we can use:

otp_set = [ui.input(on_change=lambda i=i: focus(i+1)) for i in range(4)]
otp_set[0].props('autofocus')

def focus(i: int) -> None:
    if i < len(otp_set):
        ui.run_javascript(f'getElement({otp_set[i].id}).$refs.qRef.focus()')

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@Anindya088
Comment options

Answer selected by Anindya088
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants