In ComboBox, Enter Key needs to be pressed twice for onOK event.

asked 2014-08-05 06:14:47 +0800

harsh2014 gravatar image harsh2014
3 2

updated 2014-08-05 07:51:29 +0800

I have a ComboBox and I want to call a function when Enter key is pressed when the cursor is inside this ComboBox. However on a single Enter Key press, function is not called, when Enter key is pressed twice then only the function is called. The ComboBox zul code is

<combobox id="searchBox" autodrop="true" buttonVisible="false" value="Search Text..." onFocus='self.setValue("")' onBlur='self.setValue("Search Text...")' onOK="@command('hello')" onChange="@command('setKeyword')" onSelect="@command('displaySiteInfo')"></combobox>

and the function in the ViewModel is :

    public void hello() {
        System.out.println("Hello, Enter Key is pressed");

So, on pressing the Enter key twice I get a single output "Hello, Enter Key is pressed" instead of twice

delete flag offensive retag edit

2 Answers

Sort by ยป oldest newest most voted

answered 2014-08-05 10:11:46 +0800

srigalamilitan gravatar image srigalamilitan

your code, work's for me..

link publish delete flag offensive edit

answered 2014-08-06 05:19:10 +0800

cor3000 gravatar image cor3000
4406 2 7
ZK Team


your observation is right. I created this zk fiddle

The behaviour is as expected from the source code of the widget.

A user usually does not expect the input to "commit" its value when he presses enter while choosing an item from a combobox.

When the dropdown is open the Enter/ESC keys have a special meaning -> to close the dropdown. You can disable autodrop="false" to prevent the drop down from opening automatically while typing. Then enter causes immediately an onOK.

You can use the onChange event to handle the value change after the selection from the dropdown directly.

I also used the placeholder="Search Text..." attibute to show a simpler way than your blur/focus approach.

link publish delete flag offensive edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

1 follower



Asked: 2014-08-05 06:14:47 +0800

Seen: 44 times

Last updated: Aug 06 '14

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More