As you can see the optionGroup contains a String with the items.
In some cases I want to set one of the items to readonly where selecting this one item should not be possible.
I can change the readonly for the complete optionGroup but don’t know how to set one item to readonly.
Can someone tell me if this is possible with Vaadin (using version 6.2.5) and if so how it can be done.
Unfortunately, OptionGroup doesn’t support this feature. But there is an enchantment
ticket about it. A work around for the issue would be to use two OptionGroups, one for enabled items and another for disabled ones.
We’ll just have to wait then for a new version of Vaadin.
Meanwhile we fixed it by showing an error message if the option is clicked when it should be disabled and automatically select the second option again.
This post is too old, and no longuer true. The option’s value is ised as ItemId, necessary for OptionGroup’s disabledSet.
class SiteLanguagesOptionGroupFactory<D extends SelectFieldDefinition> extends OptionGroupFieldFactory {
@Override
public List<SelectFieldOptionDefinition> getSelectFieldOptionDefinition() {
List<SelectFieldOptionDefinition> res = new ArrayList<>();
Collection<Locale> locales = getLocales();
for (Locale l : locales) {
res.add(createOption(l));
}
return res;
}
/**
* Configure a new {@link SelectFieldOptionDefinition} with give Locale language.
*
* @param l The Locale to be represented by the generated option.
*
* @return The option whose value is the Locale's language and label is Locale's
* DisplayLanguage as returned by {@link Locale#getDisplayLanguage()}
*/
private SelectFieldOptionDefinition createOption(Locale l) {
SelectFieldOptionDefinition option = new SelectFieldOptionDefinition();
option.setLabel(l.getDisplayLanguage());
option.setValue(l.getLanguage());
option.setName(l.getLanguage());
if (i18nContentSupport.getFallbackLocale().equals(l)) {
option.setSelected(true);
((OptionGroup) select).setItemEnabled(option.getValue(), false); // <-- HERE
}
return option;
}
}