Page 1 of 1

Set focus to a textfield in a TabPanel

Posted: Tue Feb 02, 2016 7:39 am
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

Re: Set focus to a textfield in a TabPanel

Posted: Tue Feb 02, 2016 9:56 am
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.

Re: Set focus to a textfield in a TabPanel

Posted: Tue Feb 02, 2016 11:07 am
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);
}

Re: Set focus to a textfield in a TabPanel

Posted: Tue Feb 02, 2016 2:30 pm
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.

Re: Set focus to a textfield in a TabPanel

Posted: Wed Feb 03, 2016 3:25 am
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