-
FEATURED COMPONENTS
First time here? Check out the FAQ!
..can more functionality be provided than in this example?
http://www.zkoss.org/zkdemo/listbox/keystroke_command
consider a list of file names and by pressing a letter, let's just assume letter b, the first file name beginning with the letter b is selected. how can this be resolved in zk? it is not a control key, therefore, the ctrlKey and onCtrlKey cannot be used.
Hi,
I think something like this will do the trick for you:
<?page title="new page title" contentType="text/html;charset=UTF-8"?> <zk xmlns:w="http://www.zkoss.org/2005/zk/client"> <script type="text/javascript" defer="true"><![CDATA[ function detectKey(e) { var evtobj=window.event? event : e var unicode=evtobj.charCode? evtobj.charCode : evtobj.keyCode var actualkey=String.fromCharCode(unicode) zAu.send(new zk.Event(zk.Widget.$("$winDetector"), "onUser", actualkey)) } document.onkeypress = detectKey ]]></script> <zscript><![CDATA[ List items = new ArrayList(50); for (int i = 0; i<100; i++) { items.add("" + i); } ]]></zscript> <window id="winDetector"> <attribute name="onUser"><![CDATA[ for (int index = 0; index<50; index++) { String s = items.get(index); if (s.startsWith((String)event.getData())) { listbox.setSelectedIndex(index); break; } } ]]> </attribute> <listbox id="listbox" height="150px" fixedLayout="true"> <listitem forEach="${items}"> <listcell label="${each}" /> </listitem> </listbox> </window> </zk>
Hope that helps
/costas
Asked: 2011-08-22 09:16:23 +0800
Seen: 579 times
Last updated: Sep 16 '11