EasyUI Forum

General Category => General Discussion => Topic started by: gordis gmbh on March 15, 2016, 10:03:46 AM



Title: How can I make sure that an item is selected in a combobox?
Post by: gordis gmbh on March 15, 2016, 10:03:46 AM
How can I make sure that an item is selected in a combobox?

I cannot depend on getValue because when I type some text in the textfield of combobox which doesn't exist as an item in the list and call getValue on it, it returns the typed text as value!

In my opinion, the getValue should be null if no item in combobox is selected.

Please help.



Title: Re: How can I make sure that an item is selected in a combobox?
Post by: jarry on March 15, 2016, 03:19:10 PM
Please refer to this topic http://www.jeasyui.com/forum/index.php?topic=3364.msg7623#msg7623


Title: Re: How can I make sure that an item is selected in a combobox?
Post by: gordis gmbh on March 17, 2016, 09:44:58 AM
Thanks for the reply but the suggested solution hangs the brouser.

The validator inList gets called for every key stroke and if the number of items in the list is slightly big then the browser hangs because of repetead iteration thru the list data.

Secondly, because the validator inList requires the combobox-selector as param, the validType cannot be set generically to all comboboxes.

Please correct me if am wrong but why is getValue returning the typed text when no item from the list is yet selected. Isn't this a bug? The method 'getText' is there to get the displayed text.

The whole thing would be easy if 'getValue' returns null / undefined / previously seleted value if no new item in the list is selected.



Title: Re: How can I make sure that an item is selected in a combobox?
Post by: jarry on March 18, 2016, 12:00:32 AM
The value can not be stored as null although the inputing value does not exist in the drop-down list. But if you type something on the inputing box and then press 'ENTER' to do the selection action, the un-existing value will be cleared. If you have a strict rule to prevent from this issue, you can bind a 'blur' event to the inputing box to trigger the 'ENTER' keydown event.
Code:
$('#cc').combobox({
inputEvents: $.extend({}, $.fn.combobox.defaults.inputEvents, {
blur: function(){
var event = new $.Event('keydown');
event.keyCode = 13;
$(this).trigger(event)
}
})
})

The solution can be found in http://www.jeasyui.com/forum/index.php?topic=5381.0