How set focus to input field on popup?

How set focus to input field on popup?



In our mobile app there is a popup with input field. I would like that field to be on focus when popup opens. I was trying to set using JS Node with this code:


passing input widget id as an input parameter. However when the code fires after showing the popup there is an error in console "null is not an object...". The id is sent properly (I have it in console output) and running code in console manually when the popup is displayed works correctly. I suspect there is a delay in popup displaying and running next node.

I managed to overcome this issue by adding the web-block to popup and run JS on its OnReady event but I was wondering is it the best way to do it or there is a popup parameters or related actions that I might be missing?

Thank you.

Hi Mykola,

Have you tried setting the autofocus attribute of the Input? (in the extended properties), without any value.

Hope this helps!

Hi Jorge,

without value it doesn't render this property at all. Setting it to true works. Cool! It only works with empty input field though but it's ok for our use case.

But I've noticed that on mobile app all advanced attributes are not rendered into code until it has name like "data-***" or at least testing with property name "test" and "data-test" resulted in this.


The proper way to define an extended property that does not have value is something like:


= "autofocus"

The browser (or mobile) shouldn't check the value, just that the attribute is present.

Regarding the error, where are you setting the JavaScript? If the element Id is properly defined (without the # in this case), you must check the place where the JavaScript is called, as it seems the DOM is not there yet, as when we try to deal with the DOM in the initialization. The OnReady action is the correct place, or a web block/expression/html widget after the element.

Hope this helps.


Eduardo Jauch