I have a Disabled TextField component which should be enabled and on focus when I click on a button. The TextField becomes enabled but focus does not change on the first click.
This is the script I have made:
I’d say there’s a delay on the view learning that the component is enabled and that the focus() command is fired before it’s ready.
from time import sleep
self.getSibling("TextField").props.enabled = True
sleep(0.1)
self.getSibling("TextField").focus()
works in Designer. I didn’t try it in a browser so you might need to test and increase the delay slightly.
This variation has the advantage of exiting as soon as possible and may feel a little more responsive but at the expense of five lines of code rather than the single sleep() instruction. A Python expert may be able to compress it for you.
self.getSibling("TextField").props.enabled = True
i = 0
while i < 100:
i += 1
if self.getSibling("TextField").props.enabled == True:
break
self.getSibling("TextField").focus()