Closed peterdresslar closed 8 years ago
My mistake, sorry. Was trying to accomplish something like this:
private void addNewStringAsSelectedOption(String name) {
Select select = new Select();
Option newOpt = new Option();
//do stuff
newOpt.setId(name);
//want to add newOpt to select as selected, but want to leave existing selections selected
List<Option> selectedOpts = select.getAllSelectedOptions();
selectedOpts.add(newOpt);
List<String> newSelectedValues = new ArrayList<>(0);
for Option o : selectedOpts {
newSelectedValues.add(o.getName());
}
select.setSelectedValue(newSelectedValues);
}
This itself could be a method but I do not know if it would be appropriate to extend the API that far
Ok now I understand well :-)
But to do this, you don't have to call the setSelectedValue(newSelectedValues)
method. You could just do something like this:
MultipleSelect select = new MultipleSelect();
Option newOpt = new Option();
newOpt.setId(name);
newOpt.setSelected(true);
select.add(newOpt);
select.refresh(); // or maybe select.render();
Ah, it was select.refresh();
that eluded us. That works. Still the methods might be useful elsewhere, thanks for the help
I will make an another PR to fix this issue. Thanks