Setting focus back to the current field on field change

Discussions about Forms Designer for SharePoint 2013 / 2016 and Office 365.
Locked
Stu
Posts: 23
Joined: Tue May 10, 2016

10 May 2016

I am trying to set focus back to the field that I am currently changing when click tab and the field fails validation.

When the form loads I set focus to $('.ScanBarcode-field').focus(); which works. When the user enters a value and hits "tab"
fd.field('ScanBarcode').change(function(){
//Validation rules fail
$('.ScanBarcode-field input').focus();
});
I am expecting the focus to return to the field that just changed. What am I missing?
Thanks

User avatar
rostislav
Moderator
Posts: 364
Joined: Mon Oct 19, 2015

11 May 2016

It could be a number of reasons, but my initial question is why are you doing

Code: Select all

$('.ScanBarcode-field input').focus();
when

Code: Select all

$('.ScanBarcode-field').focus();
is as you say what works?

Stu
Posts: 23
Joined: Tue May 10, 2016

11 May 2016

Hi Rostislav

No reason, I have tried so many variations i must have added "input" to see if it worked. I changed back to "$('.ScanBarcode-field').focus();" and still not working.

Thanks

Stu
Posts: 23
Joined: Tue May 10, 2016

12 May 2016

Are there any other sugestions?

Thanks

User avatar
rostislav
Moderator
Posts: 364
Joined: Mon Oct 19, 2015

12 May 2016

I assume ScanBarcode is a text field. Try this:

Code: Select all

fd.field('ScanBarcode').change(function(){
	setTimeout(function(){
		$('.ScanBarcode-field input').focus();
	},0);
});

Stu
Posts: 23
Joined: Tue May 10, 2016

12 May 2016

Thanks that worked.

Locked
  • Information
  • Who is online

    Users browsing this forum: No registered users and 11 guests