Set focus to a textfield in a TabPanel

Use this board to ask questions or have discussions with other Rich Displays users.
Post Reply
NickHenig
New User
Posts: 8
Joined: Tue Sep 01, 2015 6:54 am
First Name: Nick
Last Name: Henig
Company Name: L.Stroetmann Gruppe
Phone: +492517182299
Address 1: Harkortstraße 30
City: Münster
State / Province: Outside Canada/USA
Zip / Postal Code: 48163
Country: Germany
Contact:

Set focus to a textfield in a TabPanel

Post by NickHenig »

Hello,

I'm trying to set the focus to a specific Textbox, if the user changes the ActiveTab of a TabPanel.
That’s my code on the OnTabClick Event of the TabPanel.
if (tab == 0)
{
$( "TP1_ARTNR" ).focus();
}
else if (tab == 1)
{
$( "TP2_BLAGN1" ).focus();
}
But that don’t work. … can anyone tell me, what’s wrong?

regards
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: Set focus to a textfield in a TabPanel

Post by Scott Klement »

most likely it's a timing error. Possibly Profound UI is setting focus on something else after your code tries to do it.

You could try running your focus() on a timeout so that it occurs 1/2 second later than the ontabclick, for example, and see if that helps.
NickHenig
New User
Posts: 8
Joined: Tue Sep 01, 2015 6:54 am
First Name: Nick
Last Name: Henig
Company Name: L.Stroetmann Gruppe
Phone: +492517182299
Address 1: Harkortstraße 30
City: Münster
State / Province: Outside Canada/USA
Zip / Postal Code: 48163
Country: Germany
Contact:

Re: Set focus to a textfield in a TabPanel

Post by NickHenig »

hi,

do you mean something like that? ... It does not work.

function focusTP1ARTN()
{
alert("1");
$( "TP1_ARTNR" ).focus();
}
function focusTP2BLAGN1()
{
$( "TP2_BLAGN1" ).focus();
}

if (tab == 0)
{
window.setTimeout("focusTP1ARTN();", 5000);
}
else if (tab == 1)
{
window.setTimeout("focusTP2BLAGN1();", 5000);
}
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: Set focus to a textfield in a TabPanel

Post by Scott Klement »

By putting quotes around the function names, it'll think it's a string rather than a function, so you don't want to do that. Assuming the rest of your code is correct (I don't use jQuery, personally) you'd do this:

Code: Select all

function focusTP1ARTN()
{
   alert("1");
   $( "TP1_ARTNR" ).focus();
}
function focusTP2BLAGN1()
{
   $( "TP2_BLAGN1" ).focus();
}

if (tab == 0)
{
   window.setTimeout(focusTP1ARTN, 5000);
}
else if (tab == 1)
{
   window.setTimeout(focusTP2BLAGN1, 5000);
}

Personally, I don't see the value of creating functions for each field, and I don't use jQuery, so my code, using the Profound UI framework work look like this (untested):

Code: Select all

if (tab == 0) {
   setTimeout(function() { getObj("TP1_ARTNR").focus() }, 5000);
}
else if (tab == 1) {
   setTimeout(function() { getObj("TP2_BLAGN1").focus() }, 5000);
}
And, of course, the 5 second timeout is probably overkill... once you get it working, you'll want to set that to a much smaller number.
NickHenig
New User
Posts: 8
Joined: Tue Sep 01, 2015 6:54 am
First Name: Nick
Last Name: Henig
Company Name: L.Stroetmann Gruppe
Phone: +492517182299
Address 1: Harkortstraße 30
City: Münster
State / Province: Outside Canada/USA
Zip / Postal Code: 48163
Country: Germany
Contact:

Re: Set focus to a textfield in a TabPanel

Post by NickHenig »

Hi,

thank you very much. That works for me.
Profound and JavaScript are pretty new for me an I'm often in the dark ... :D
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest