gwtbootstrap3 / gwtbootstrap3-extras

Extra (third party) wrappers for GwtBootstrap3
Apache License 2.0
43 stars 89 forks source link

Fixes issue #279 #280

Closed peterdresslar closed 8 years ago

crevete commented 8 years ago

I will make an another PR to fix this issue. Thanks

peterdresslar commented 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

crevete commented 8 years ago

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();
peterdresslar commented 8 years ago

Ah, it was select.refresh(); that eluded us. That works. Still the methods might be useful elsewhere, thanks for the help