cancel
Showing results for 
Search instead for 
Did you mean: 

Set Input field focus on Init

Former Member
0 Kudos

Hi,

I want to set focus on input field on first load of the form.

I use next code

IWDAttributeInfo attribute = wdContext.nodeSearchInput().getNodeInfo().getAttribute(IPrivateSearchSDCompView.ISearchInputElement.SEARCH_INPUT);

wdThis.wdGetAPI().requestFocus(wdContext.currentSearchInputElement(), attribute);

which put in wdDoModifyView .

The code doesn't work when page is load for first time.

Input field is in ViewContainerUIElement which is in Tab.

May be I have to put focus first on container ? (don't know how)

Can any one suggest me how to fix this problem.

Best Regards,

Dimitar

Accepted Solutions (0)

Answers (2)

Answers (2)

susmita_panigrahi
Active Participant
0 Kudos

Hi Velinov,

Put the above mentioned code in the WdDoInit() method of view where the inputfield is there.

Thanks

Susmita

gill367
Active Contributor
0 Kudos

Hello Dimitar,

try the following code

if(firstTime)
		{
			IWDInputField InputField = (IWDInputField) view.getElement("INPUT_1");
		
			InputField.requestFocus();
		
		}

where INPUT_1 is the ID of the input field to which you want to set the focus.

Hope it will solve your problem.

Regards,

Sarbjeet Singh

Former Member
0 Kudos

Hi Sarbjeet,

I tryed this code but result is the same.

Solution works but not on first load.

Thanks.

Best Regards,

Dimitar

Former Member
0 Kudos

Hai Sarbjeet,

I tried your solution to set focus on inputfield for first time , Its working fine

Regards,

Krish

Former Member
0 Kudos

Thanks Sarbjeet Singh,

I tried the same & it is working..

@Dimitar: If your issue is resolved, then pls mark it as answered. Don't forget to appreciate sarbjeet, if his solution resolved your issue.

Thanks & Regards

Hussain

Former Member
0 Kudos

Hi Dimitar Velinov,

If you want to set focus on the first load of UI then you must use the wdDoInit() method because wdDoModify() doesn't execute at first time it get executed whenever any modification in UI happens.

Second you should not use wdDoModify() without any suitable condition as you have done in your code snippet. if you want to set the focus more then one time or again and again then better create one method and call it. It will put an impact on performance and maintainability.

Regards

Jeetendra