-
FEATURED COMPONENTS
First time here? Check out the FAQ!
I have a grid of intboxes with a variable number of rows and cols and want to catch the arrow keys to navigate among them. I've ported over the documentation and am still confused as to how to do it, especially with MVVM. Here is the grid I'm working with. Can someone give me an idea how to do it?
It's actually pretty straight forward :
ctrlKeys="#up" onCtrlKey="@command('keyPressed')"
java :
@Command
public void keyPressed(@ContextParam(ContextType.TRIGGER_EVENT) KeyEvent event) {
Clients.showNotification("pressed : " + event.getKeyCode());
}
Well I've updated the fiddle again, only for right key and down key.
@Command
public void keyPressed(@ContextParam(ContextType.TRIGGER_EVENT) KeyEvent event) {
InputElement comp = (InputElement) event.getTarget();
if (event.getKeyCode() == 39) {
Component nextSybling = comp.getParent().getNextSibling() == null ? comp.getParent().getParent().getFirstChild().getFirstChild() : comp.getParent().getNextSibling().getFirstChild();
while (!(nextSybling instanceof InputElement)) {
nextSybling = nextSybling.getParent().getNextSibling() == null ? comp.getParent().getParent().getFirstChild().getFirstChild() : nextSybling.getParent().getNextSibling().getFirstChild();
}
((InputElement) nextSybling).setFocus(true);
} else if (event.getKeyCode() == 40) {
int tabIndex = comp.getTabindex();
Component nextRow = comp.getParent().getParent().getNextSibling() == null ? comp.getParent().getParent().getParent().getFirstChild() : comp.getParent().getParent().getNextSibling();
Component next = nextRow.getFirstChild().getFirstChild();
while (!(next instanceof InputElement) || ((InputElement) next).getTabindex() != tabIndex) {
next = next.getParent().getNextSibling().getFirstChild();
}
((InputElement) next).setFocus(true);
}
}
And in the zul I've changed also :
<intbox tabindex="${forEachStatus.index}"
So I could navigate under and know at what position I was.
Also in the implementation : end of row or line, goto beginning.
The right key has also the feature if you swap more of template, it still work (tested it with swapping template on foreachstatus.index%2==0).
For key down, the tabindex must be same for a inputelement or there are problems.
Greetz chill.
Hi Chill
The challenge will be when user press down arrow key, we need to move down on same column and when up key, move up on the same column.
Do you have example for that please ?
Asked: 2015-03-23 20:33:57 +0800
Seen: 20 times
Last updated: Mar 24 '15