PDA

View Full Version : Using tabtarget with windowlists



Spyke
May 11th, 2008, 12:53
Is there any way to set a tab target to the first item in a windowlist?

For example, if I've got a list of language items in a list:


<windowlist name="languagelist">
with the first item in the class called language_name:



<windowclass name="charsheet_languagelistitem">
<sheetdata>
<textlistitemvalue name="language_name">
...
Can I make the focus shift to that field on pressing tab?

I've tried both languagelist and language_name as follows:



<tabtarget>
<next>languagelist</next>
</tabtarget>

And also languagelist[1], languagelist.language_name and languagelist.language_name[1]!

Any help much appreciated.

Spyke

Foen
May 11th, 2008, 13:33
This can be done, using some scripting and the onTab event.

Assuming the following sequential layout on your page:

'name' stringcontrol
'languagelist' windowlistcontrol, with 'languagename' stringcontrol in each element
'notes' stringcontrol


The 'name' stringcontrol must have its onTab event handled, which takes a single boolean parameter 'forward' (forward=true means TAB was pressed, forward=false means SHIFT-TAB was pressed). The event handler looks like this:



'name' script block

function onTab(forward)
if forward then
window.languagelist.tabFirst();
else
window.notes.setFocus();
end
end


The languagelist control then needs to expose a number of helper functions. tabFirst sets the focus on the first list entry, tabLast sets the focus on the last list entry, tabNext(win) advances the focus to the next entry after win and tabPrev(win) does the reverse.



'languagelist' script block

function tabFirst()
tabNext(nil);
end

function tabLast()
tabPrev(nil);
end

function tabNext(win)
win = getNextWindow(win);
if win then
win.languagename.setFocus();
elseif nextControl then
nextControl.setFocus();
end
end

function tabPrev(win)
win = getPrevWindow(win);
if win then
win.languagename.setFocus();
elseif prevControl then
prevControl.setFocus();
end
end


Two variables are also used here 'nextControl' and 'prevControl' so that tabbing out of the list is allowed. Set these up by adding <tabtarget><next>notes</next><prev>name</prev></tabtarget> to the languagelist, and the following code to the languagelist script block:



'languagelist' script block

local nextControl = nil;
local prevControl = nil;

function onInit()
if tabtarget and tabtarget[1].next then
local ctrl = tabtarget[1].next[1];
nextControl = window[ctrl];
end
if tabtarget and tabtarget[1].prev then
local ctrl = tabtarget[1].prev[1];
prevControl = window[ctrl];
end
end


Next the language windowclass (displayed in languagelist) needs an onTab handler for its languagename stringcontrol:



'languagename' script block

function onTab(forward)
if forward then
window.windowlist.tabNext(window);
else
window.windowlist.tabPrev(window);
end
end


Finally, the 'notes' stringcontrol needs an onTab handler too:



'notes' script block

function onTab(forward)
if forward then
window.name.setFocus();
else
window.languagelist.tabLast();
end
end


Phew! This code should allow you tab into, through and out of a windowlist control. There is a big catch however: stringcontrols (and stringfields) expose an onTab event, but numbercontrols (and numberfields) do not. This is a real pain, and requires you either to rearrange your window so that strings sit either side of the window lists (and at the beginning and end of each nested windowclass in the list), or insert dummy stringcontrols on each side of a numbercontrol.

If you get stuck, just give me a shout!

Stuart

Spyke
May 11th, 2008, 23:11
Brilliant. It all made sense and works like a charm.

Thanks very, very much, Stuart, for such a detailed reply.

Spyke

Foen
May 11th, 2008, 23:22
My pleasure!

It would be good to see some of this functionality added to the core engine, or at least have onTab etc exposed for numbercontrol (and numberfield) controls.

All the best

Stuart

joshuha
May 12th, 2008, 15:09
How about a feature request to have the ability for the tab <prev> and <next> support a prevwin/nextwin type functionality for use in windowlists?

Or would you prefer it to jsut be exposed for the numbercontrols and handle it yourself?

Foen
May 13th, 2008, 06:38
I imagine the functionality in windowlists would be hard to implement, though I'd be delighted if it was included in the core FG engine.

In the mean time, onTab for numbercontrols would be a great boon (as would the other keyboard/editing events such as onDeleteX, onEnter and onNavigateX). I have already added those to a previous thread on ruleset functionality, I think.

Stuart