EasyUI Forum
May 18, 2024, 10:16:03 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: How can I make sure that an item is selected in a combobox?  (Read 7578 times)
gordis gmbh
Full Member
***
Posts: 103


View Profile Email
« 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.

Logged
jarry
Administrator
Hero Member
*****
Posts: 2264


View Profile Email
« Reply #1 on: March 15, 2016, 03:19:10 PM »

Please refer to this topic http://www.jeasyui.com/forum/index.php?topic=3364.msg7623#msg7623
Logged
gordis gmbh
Full Member
***
Posts: 103


View Profile Email
« Reply #2 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.

« Last Edit: March 17, 2016, 09:48:32 AM by sarathi » Logged
jarry
Administrator
Hero Member
*****
Posts: 2264


View Profile Email
« Reply #3 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
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!