Need help regarding.selectall functionality. I have created a form.
DynamicForm form = new DynamicForm();
final SelectItem category = new SelectItem("category", "Employee Category");
category.setMultiple(true);
category.setValueMap("Direct","InDirect","ALL");
form.setFields(category);
If i select 'ALL' all three items in picklist should also be selected.if i deselect 'ALL' all three items should be deseleted. need help
You can try out the following:
boolean isAllSelected = false; // global variable
SelectItem selectItem = new SelectItem("category", "Employee Category");
selectItem.setMultiple(true);
selectItem.setMultipleAppearance(MultipleAppearance.PICKLIST);
selectItem.setValueMap("Direct","InDirect","ALL");
selectItem.addChangedHandler(new ChangedHandler() {
@Override
public void onChanged(ChangedEvent event) {
if (event.getValue() != null) {
if (event.getValue().toString().contains("ALL")) {
if (!isAllSelected) {
selectItem.setValues("Direct","InDirect", "ALL");
isAllSelected = true;
}
} else {
if (isAllSelected) {
selectItem.clearValue();
}
isAllSelected = false;
}
} else {
isAllSelected = false;
}
}
});
DynamicForm form = new DynamicForm();
form.setSize("800px", "400px");
form.setFields(selectItem);
form.draw();