View Full Version : CheckBox Values In ComboBox

23 Aug 2010, 10:44 AM
Hi, is there a way to display a drop-down list (aka ComboBox) that contains checkbox items rather than text strings? If not, is there any way to support multiple selection in a drop-down list?

23 Aug 2010, 10:47 AM
You can use a custom template in your ComboBox that renders checkboxes which you can check.

If you want multiply selection, i would either extend ComboBox or TriggerField and add the feature. Depending on the exact features you need, you have to decide between adding the features to ComboBox or creating them again on TriggerField.

24 Aug 2010, 3:59 AM
Thanks, could you please provide a code sample of the custom template as well as how I would integrate it using Java code, including retrieving the checkbox values? Thanks!

24 Aug 2010, 4:05 AM
How to use custom templates can be seen here: http://www.sencha.com/examples/explorer.html#combobox

Simple but a checkbox into the markup.

24 Aug 2010, 4:52 AM
Great, thanks! I have the templates working but how would I get the selected checkboxes from the combobox? I tried the following but it didn't work:

protected void createDropDown(ObjectAttributeDefinitionJO attribute)
ListStore<ObjectAttributeValueDefinitionJO> store = new ListStore<ObjectAttributeValueDefinitionJO>();
store.setDefaultSort(ObjectAttributeValueDefinitionJO.STRINGVALUE, SortDir.ASC);

Iterator<ObjectAttributeValueDefinitionJO> iter = attribute.getValueDefinitions().iterator();

while (iter.hasNext())
ObjectAttributeValueDefinitionJO defn = iter.next();


store.sort(ObjectAttributeValueDefinitionJO.STRINGVALUE, SortDir.ASC);

final ComboBox<ObjectAttributeValueDefinitionJO> comboBoxField = new ComboBox<ObjectAttributeValueDefinitionJO>();

List<ObjectAttributeValueDefinitionJO> selections = comboBoxField.getSelection();

if (selections != null)
Iterator<ObjectAttributeValueDefinitionJO> selectionsIter = selections.iterator();

while (selectionsIter.hasNext())
ObjectAttributeValueDefinitionJO defn = selectionsIter.next();

System.out.println("defn.getStringValue() = " + defn.getStringValue());

private native String getCheckBoxTemplate() /*-{
return [
'<tpl for=".">',
'<input type="checkbox" checked="checked" name="{id}" value="{stringValue}" />{displayValue} ({stringValue})<br/>',

26 Aug 2010, 9:45 AM
Are there any plans to add a multi-select Check ComboBox in the future?