简体   繁体   中英

how to change the default behaviour of struts2 select dropdown list

I have a struts2 select drop down list which has numbers. I need to select a particular number in it using keyboard numbers which was default and it works but in this I need more specific to disable the behaviour that is while say for an example if I need 25 I can type 2 and 5 but if I type 2 and with a delay in typing 5, then it is not working so only 20 is selected instead of 25.

Another one is I need to disable the behaviour that when 2 is pressed and with some delay 2 is pressed again then it starts increments the number by 1 like 20,21,22... and so on up to 29.

The behaviour that while I needed is that the struts2 drop down list should only select what I type exactly.

<s:select list="#{'0':'00','1':'01','2':'02','3':'03','4':'04','5':'05','6':'06','7':'07','8':'08',                 '9':'09','10':'10','11':'11','12':'12','13':'13','14':'14','15':'15','16':'16','17':'17','18':'18','19':'19','20':'20','21':'21','22':'22','23':'23','24':'24'}"  
name="workedHours" cssClass=" disable inputboxsmall" id="workedHours" onchange="calcTotTime()"/>

That is browser-specific, Struts2 is not involved at all;

for example, Firefox behaves like you described since very old versions, while in IE6 (!) if you press 2 and 5, he looks for "starting with 2" and then "starting with 5" (it will never find 25 by keyboard).

You can use jQuery to add the custom behavior to your Selects, once the page is ready.

For example, add a javascript function call in onkeyup event, that remember the previously digited characters, append the new character to them and re-assign the selected attribute to the new corresponding element.

Then you would have to handle the exceptions (no element matches, do nothing or what ?), and decide how to make possible to the user to re-start from the beginning. With a timer, like browsers do, you haven't this problem, but if you override the timer, you should find another way (hot-key or something).

Personally, i don't think that overriding browsers behavior is a good thing, especially because they're already optimized for the most of the use-cases...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM