PDA

View Full Version : Inserting empty value to a combobox



blackbox23
6 Dec 2010, 6:34 AM
Hello,

I really hope someone could help me out on this one. Been trying to figure this out for 3 days now.

I want to insert an empty value to a combo box drop down list. I did this by adding a modeldata with "&nbsp" as the displayfield. The drop down list displays correctly..(please see code 1/attachment 1). However when I select it, the combobox field also displays "&nbsp", so I added a ListModelPropertyEditor and overrode getStringValue, but it doesn't work, and. worse, the drop down list doesnt work too. (please see code2/attachment 2).

Here's my code:

code1:



final ComboBox<ModelData> combo = new ComboBox<ModelData>();
combo.setFieldLabel("test");
ListStore<ModelData> store = new ListStore<ModelData>();
combo.setStore(store);
combo.setDisplayField("display");
combo.setTriggerAction(TriggerAction.ALL);



ModelData m = new BaseModelData();
m.set("display", "&nbsp");
m.set("value", 1);
store.add(m);

m = new BaseModelData();
m.set("display", "2");
m.set("value", 2);
store.add(m);

fp.add(combo, new FormData("-20"));

code2:


final ComboBox<ModelData> combo = new ComboBox<ModelData>();
combo.setFieldLabel("test");
ListStore<ModelData> store = new ListStore<ModelData>();
combo.setStore(store);
combo.setDisplayField("display");
combo.setTriggerAction(TriggerAction.ALL);
combo.setPropertyEditor(new ListModelPropertyEditor<ModelData>() {
@Override
public String getStringValue(ModelData value) {
if (value.get("display").equals("&nbsp")) {
return "";
}
return (String) value.get("display");
}
});


ModelData m = new BaseModelData();
m.set("display", "&nbsp");
m.set("value", 1);
store.add(m);

m = new BaseModelData();
m.set("display", "2");
m.set("value", 2);
store.add(m);

fp.add(combo, new FormData("-20"));



I'm using GXT 2.1.1/GXT2.0. Please help me.


Thanks.

sven
6 Dec 2010, 6:37 AM
You can for example change the template and add a height to the used markup. Another solution would be to use a ModelProcessor and fill a custom field with "&nbsp;" that gets displayed in the template.

In both ways you probably have to extend ComboBox and override getValue(), because that returns null if the raw value is an empty string.

blackbox23
6 Dec 2010, 6:49 AM
Hi Sven,

i Really hate to say this. But I don't have an idea how to do just that. I'm not that familiar with using templates. Can you point me to an example on how to do just that?

Thank you

sven
6 Dec 2010, 6:51 AM
http://www.sencha.com/examples/explorer.html#combobox
This example uses custom templats. Simple add a height to the markup, like 20px for example.

blackbox23
6 Dec 2010, 7:02 AM
I just added a template without even setting the height and it worked:

private native String getTemplate() /*-{
return [
'<tpl for=".">',
'<div class="x-combo-list-item">{[values.display]}</div>',
'</tpl>'
].join("");
}-*/;

thanks a lot man.