EasyUI Forum
April 23, 2024, 04:09:59 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Combobox setText  (Read 9076 times)
y.bykov
Newbie
*
Posts: 49


View Profile
« on: March 15, 2017, 05:45:55 AM »

Is it possible to change view text after select value in combobox?
I use groupField and want that after value select text will change to group_name::value_name.
If use onSelect handler this text change but after this EasyUI change it to value_name again in combo plugin.
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: March 15, 2017, 08:03:03 AM »

Please try this code:
Code:
$('#cc').combobox({
onChange: function(value){
var opts = $(this).combobox('options');
var row = opts.finder.getRow(this, value);
if (row){
$(this).combobox('setText', row[opts.groupField]+':'+row[opts.textField]);
}
}
})
Logged
y.bykov
Newbie
*
Posts: 49


View Profile
« Reply #2 on: March 15, 2017, 12:16:02 PM »

Thank you!
Logged
y.bykov
Newbie
*
Posts: 49


View Profile
« Reply #3 on: May 04, 2017, 04:44:17 AM »

If I use {limitToList: true} in combobox, row[opts.groupField]+':' string part reset and stay only row[opts.textField].
Is it possible to fix for save previous onChange behaviour?
Thank you
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #4 on: May 04, 2017, 06:56:03 PM »

You can override the 'setValue' and 'setValues' methods to set your customized text on the inputing box.
Code:
(function($){
var setValues = $.fn.combobox.methods.setValues;
$.extend($.fn.combobox.methods, {
setValues: function(jq, values){
return jq.each(function(){
setValues($(this), values);
var opts = $(this).combobox('options');
if (opts.groupField){
var vv = $(this).combobox('getValues');
var ss = $(this).combobox('getText').split(opts.separator);
for(var i=0; i<vv.length; i++){
var row = opts.finder.getRow(this, vv[i]);
if (row){
ss[i] = row[opts.groupField]+':'+row[opts.textField]
}
}
$(this).combobox('setText', ss.join(opts.separator));
}
})
},
setValue: function(jq, value){
return jq.each(function(){
$(this).combobox('setValues',$.isArray(value)?value:[value]);
});
}
})
})(jQuery);

Usage example:
Code:
$('#cc').combobox({
reversed: true
})
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!