-
FEATURED COMPONENTS
First time here? Check out the FAQ!
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 :
@Command
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
your code, work's for me..
Hi,
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.
Asked: 2014-08-05 06:14:47 +0800
Seen: 47 times
Last updated: Aug 06 '14