Let's follow up this discussion at the Neptune Community

(this forum will be kept in read-only mode)

Creating a Auto Focus for the input field .

Hi All , 


How we can create Auto focus functionality in the neptune application , i have one form in which i have the input field , i need to set the auto focus once the screen gets rendered . 


Please suggest me some help . 


Regards

Ashutosh


Hi Ashutosh


You can use the .focus() method to set focus in a field. The only issue is that UI5 use some time to render the UI, so it is needed to wrap it into a timeout.


Example: The field that get's focus is called inMATNR. Timeout of 500ms, should be enough for mobile devices.


 

    setTimeout(function() {
        inMATNR.focus();
    }, 500);

 


Regards

Ole Andre 

Hey Ole,

Can you tell me where the code needs to be placed? Is it placed in the form or page that holds the input or is it place placed in the input itself?

 

Hi Rex


You can place the coding where it is natural regarding the flow of the App. Example: When you navigate to a page and want the input field to get focus, use this code right after the oApp.to("NextPage"); You can use the event script editor for a press event or ajaxSuccess.


Regards

Ole Andre 

Hi,

I have a similar question, I want to set focus on input field which is on first field, can please anyone help me to understand where to place Element.focus() . I tried on the Navigate / afterNavigate events of the App with time out but it didn't help.

Please advice,


Thanks,

Leena

Hey Leena,

I'm assuming you meant, you want to have the focus on a field when your app first loads. Couple ways to do it. One way is to create a script code before any of your pages and putting the focus for the input in there. This will tell your app to put the focus on that field when it initializes.

Take a look at the below screenshot for an example:


 

Hey Rex,

Thanks for the suggestion. It worked!!



Regards,

Leena

I achieved focussing on my field using the above method. Thanks for this.


Is there also a way to automatically show the keyboard (Android) when focus is set?


Users still have to touch the (focussed) input-field to get the keyboard.

Login or Signup to post a comment