zeroed
29 Mar 2011, 6:52 AM
Hi,
What is the correct way to add empty value to combobox list?
blay
30 Mar 2011, 12:02 AM
here there is a solution:
http://www.sencha.com/forum/showthread.php?78908-How-to-add-an-empty-value-to-ComboBox
I´ve adapted it by extending comboBox in a custom class where I do two things:
a) I set the comboBox template (as the thread above says)
private native String getTemplate(String displayField) /*-{
return [
'<tpl for=".">',
'<tpl if="'+displayField+' == \'\'">',
'<div class="x-combo-list-item"></BR></div>',
'</tpl>',
'<tpl if="'+displayField+' != \'\'">',
'<div class="x-combo-list-item">{'+displayField+'}</div>',
'</tpl>',
'</tpl>'
].join("");
}-*/;
b) Add a listener to "Store.Add" event, in order to add an empty value only when store is empty and we add values to it.
if (emptyObject!=null){
getStore().addListener(Store.Add, new Listener<StoreEvent<D>>(){
public void handleEvent(StoreEvent<D> be) {
int index = be.getIndex();
if (index==0 && !be.getModels().get(0).get(getDisplayField()).equals("")){
emptyObject.set(getDisplayField(), "");
List<D> models = be.getModels();
List<D> temp = new ArrayList<D>();
temp.add(emptyObject);
temp.addAll(models);
setStore(new ListStore<D>());
getStore().add(temp);
}
}});
}
The "emptyObject" is an object of D type which has been passed in the constructor.
Powered by vBulletin® Version 4.1.5 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.