Problem setting focus in a textBox (onSelect event)

Use this board to ask questions or have discussions with other Rich Displays users.
Post Reply
Estibarna
New User
Posts: 10
Joined: Wed Sep 16, 2015 2:57 am
First Name: Sergio
Last Name: Martinez Roig
Company Name: Estibarna, CPE
State / Province: Outside Canada/USA
Country: Spain
Contact:

Problem setting focus in a textBox (onSelect event)

Post by Estibarna »

Hello,

We have tree textbox, the second one is disabled, the first one have a 'choices url' property that response with two fields ('item' and 'desc') in the first textbobx onSelect property whe have this code:

Code: Select all

function textboxSelection(rcd) {
  changeElementValue('field1',rcd['item']);
  changeElementValue('field2',rcd['desc']);
}

textboxSelection;
After select one value the fields are populated correctly, also we need to put the focus on the third field, but we don't find how do it.

we try adding this:

Code: Select all

getObj('field3').focus();
but after select one value the cursor remain in field1.

Thanks in advance,

Sergio
Scott Klement
Experienced User
Posts: 2711
Joined: Wed Aug 01, 2012 8:58 am
First Name: Scott
Last Name: Klement
Company Name: Profound Logic
City: Milwaukee
State / Province: Wisconsin

Re: Problem setting focus in a textBox (onSelect event)

Post by Scott Klement »

That looks correct.

Could it be a timing problem?
Estibarna
New User
Posts: 10
Joined: Wed Sep 16, 2015 2:57 am
First Name: Sergio
Last Name: Martinez Roig
Company Name: Estibarna, CPE
State / Province: Outside Canada/USA
Country: Spain
Contact:

Re: Problem setting focus in a textBox (onSelect event)

Post by Estibarna »

Thanks for your reply Scott,

We have made a test UI Rich Display that is attached to this messages with 3 fields,

field1 with this code in 'onFocus' event:

Code: Select all

console.log(Date.now() + " onFocus field 1");
field1 onSelect event:

Code: Select all

function prbSelect(rcd) {
  console.log(Date.now() + " onSelect field 1");
  changeElementValue('field2','Selected Option ' + rcd.field1);
  changeElementValue('field3', rcd.field1);
  getObj("field3").focus();
}

prbSelect;
field3 onFocus event:

Code: Select all

console.log(Date.now() + " onFocus field 3");
and this is the console log result when an opcion is selected in field1:
1578735274233 onFocus field 1
1578735278457 onSelect field 1
1578735278459 onFocus field 3
1578735278463 onFocus field 1
seems like when onSelect event is over the focus returns to field1

Thanks,
Attachments
prbTextC.json
(2.06 KiB) Downloaded 212 times
Estibarna
New User
Posts: 10
Joined: Wed Sep 16, 2015 2:57 am
First Name: Sergio
Last Name: Martinez Roig
Company Name: Estibarna, CPE
State / Province: Outside Canada/USA
Country: Spain
Contact:

Re: Problem setting focus in a textBox (onSelect event)

Post by Estibarna »

Another comment:

We found this behaviour, if you select an option using keyboard the focus goes to field3 but if you select an option with mouse the focus remains in field1

Thanks,

Sergio
Scott Klement
Experienced User
Posts: 2711
Joined: Wed Aug 01, 2012 8:58 am
First Name: Scott
Last Name: Klement
Company Name: Profound Logic
City: Milwaukee
State / Province: Wisconsin

Re: Problem setting focus in a textBox (onSelect event)

Post by Scott Klement »

I'm not sure that I understand the example? Looking at your display file, there is no auto-complete defined on 'field1'. However, you have defined the onselect event for this widget.

The onselect event fires when an option is selected in an autocomplete, combo box or dropdown box... it won't fire at all on a textbox, otherwise.

I'm assuming this isn't the actual display that you're using since your screenshots do show the event firing. My guess from your description is that the focus is being placed back into the textbox after an item is selected. It makes perfect sense if you think about it: Clicking one of the choices with the mouse would cause the focus to be placed on the choice you clicked. (That's normal behavior, a mouse click moves the focus.) So after the item has been clicked, Profound UI has to move the focus back to the text box.

From your tests it seems that's what's happening... after a choice is selected, the onselect event fires. Here you move focus to field3. Then Profound UI gets control again and moves the focus back to input1.

Assuming this guess is right, you could fix the problem by adding a small delay to the focus like this:

Code: Select all

setTimeout(function(){ getObj("field3").focus(); }, 5);
This causes the getObj.focus to run 5ms (means 5/1000 of a second) after the onselect event ends.
Estibarna
New User
Posts: 10
Joined: Wed Sep 16, 2015 2:57 am
First Name: Sergio
Last Name: Martinez Roig
Company Name: Estibarna, CPE
State / Province: Outside Canada/USA
Country: Spain
Contact:

Re: Problem setting focus in a textBox (onSelect event)

Post by Estibarna »

Scott,

in our example we are using choice options, the behavior is the same, and the onSelect event is fired when option is selected.

Adding this little delay works fine and as we expect.

Thanks,
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 2 guests