admin管理员组文章数量:1426066
I have an ExtJs Combobox with multiple true and I want to show "X values selected" on the input field instead of "Value 1, Value 2, Value 3". I tried with select listener but when I set the value to the input field and then you call multibo.getValue() it takes the value from the input field. I would need something like take the value from the valueField (a hidden input).
My code:
var multiCombo = Ext.create('Ext.form.field.ComboBox', {
renderTo: item.id,
multiSelect: true,
displayField: 'name',
editable: false,
valueField: 'id',
emptyText: 'Select',
hiddenName: 'data[Model][' + item.getAttribute('question-id') + '][value]',
submitValue: true,
inputType: 'hidden',
value: selectedOptions,
width: 300,
store: store,
queryMode: 'local',
listeners: {
expand: function (bo) {
var values = Ext.get(bo.hiddenDataEl.dom.lastChild).dom.value;
values = values.split(",");
Ext.each(values, function (value, i) {
values[i] = parseInt(value);
});
bo.setValue(values);
Ext.get(bo.getInputId()).dom.value = values.length + ' selected';
},
select: function (bo, values) {
if (values[values.length - 1].data.id === parseInt(item.getAttribute('not-applicable'))) {
bo.setValue(parseInt(item.getAttribute('not-applicable')));
} else {
var notApplicable = -1;
var newValues = bo.getValue();
if ((notApplicable = bo.getValue().indexOf(parseInt(item.getAttribute('not-applicable')))) != -1) {
newValues.splice(notApplicable, 1);
}
bo.setValue(newValues);
}
Ext.get(bo.hiddenDataEl.dom.lastChild).dom.value = bo.getValue().join(',');
optionsSelected = bo.getValue();
Ext.get(bo.getInputId()).dom.value = optionsSelected.length + ' selected';
},
change: function (bo) {
if (item.getAttribute('required') == 'true') {
if (bo.getValue().length == 0) {
question.findParentNode('li', 1, true).addCls("is_required");
} else {
question.findParentNode('li', 1, true).removeCls("is_required");
}
//There is no ExtJs equivalent for this
$('#' + bo.getInputId()).keyup();
}
}
}
});
I have an ExtJs Combobox with multiple true and I want to show "X values selected" on the input field instead of "Value 1, Value 2, Value 3". I tried with select listener but when I set the value to the input field and then you call multibo.getValue() it takes the value from the input field. I would need something like take the value from the valueField (a hidden input).
My code:
var multiCombo = Ext.create('Ext.form.field.ComboBox', {
renderTo: item.id,
multiSelect: true,
displayField: 'name',
editable: false,
valueField: 'id',
emptyText: 'Select',
hiddenName: 'data[Model][' + item.getAttribute('question-id') + '][value]',
submitValue: true,
inputType: 'hidden',
value: selectedOptions,
width: 300,
store: store,
queryMode: 'local',
listeners: {
expand: function (bo) {
var values = Ext.get(bo.hiddenDataEl.dom.lastChild).dom.value;
values = values.split(",");
Ext.each(values, function (value, i) {
values[i] = parseInt(value);
});
bo.setValue(values);
Ext.get(bo.getInputId()).dom.value = values.length + ' selected';
},
select: function (bo, values) {
if (values[values.length - 1].data.id === parseInt(item.getAttribute('not-applicable'))) {
bo.setValue(parseInt(item.getAttribute('not-applicable')));
} else {
var notApplicable = -1;
var newValues = bo.getValue();
if ((notApplicable = bo.getValue().indexOf(parseInt(item.getAttribute('not-applicable')))) != -1) {
newValues.splice(notApplicable, 1);
}
bo.setValue(newValues);
}
Ext.get(bo.hiddenDataEl.dom.lastChild).dom.value = bo.getValue().join(',');
optionsSelected = bo.getValue();
Ext.get(bo.getInputId()).dom.value = optionsSelected.length + ' selected';
},
change: function (bo) {
if (item.getAttribute('required') == 'true') {
if (bo.getValue().length == 0) {
question.findParentNode('li', 1, true).addCls("is_required");
} else {
question.findParentNode('li', 1, true).removeCls("is_required");
}
//There is no ExtJs equivalent for this
$('#' + bo.getInputId()).keyup();
}
}
}
});
Share
Improve this question
edited Aug 21, 2013 at 12:51
Darin Kolev
3,40913 gold badges33 silver badges47 bronze badges
asked Jul 25, 2012 at 13:50
ajibarraajibarra
581 silver badge5 bronze badges
2 Answers
Reset to default 3I'm not sure that I follow what is going on with all of the event handlers (so I may be missing something), but the simplest way to achieve what you described in your first sentence above is to provide your own implementation for the bo's getDisplayValue
method. Here it is in the docs.
Just set it up to return a count of how many values are selected. Here's an example:
var multiCombo = Ext.create('Ext.form.field.ComboBox', {
renderTo: item.id,
multiSelect: true,
displayField: 'name',
// your own getDisplayValue implementation
getDisplayValue: function() {
return multiCombo.value.length + ' values selected';
},
editable: false,
valueField: 'id',
emptyText: 'Select',
hiddenName: 'data[Model][' + item.getAttribute('question-id') + '][value]',
submitValue: true,
inputType: 'hidden',
value: selectedOptions,
width: 300,
store: store,
queryMode: 'local',
});
Also this may help:
getDisplayValue: function() {
return (this.displayTplData.length > 1) ? this.displayTplData.length + ' selected' : this.displayTplData[0].name;
},
本文标签: javascriptHow to change display message in an ExtJs ComboboxStack Overflow
版权声明:本文标题:javascript - How to change display message in an ExtJs Combobox? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745394316a2656743.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论