PDA

View Full Version : CheckBox Values In ComboBox



ccocco_dw
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?

sven
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.

ccocco_dw
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!

sven
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.

ccocco_dw
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.add(defn);
}

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

final ComboBox<ObjectAttributeValueDefinitionJO> comboBoxField = new ComboBox<ObjectAttributeValueDefinitionJO>();
comboBoxField.setEditable(false);
comboBoxField.setTriggerAction(TriggerAction.ALL);
comboBoxField.setStore(store);
comboBoxField.setDisplayField(ObjectAttributeValueDefinitionJO.STRINGVALUE);
comboBoxField.setTemplate(getCheckBoxTemplate());

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/>',
'</tpl>'
].join("");
}-*/;

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