Is it possible to disable certain items in a Wicket DropDownChoice?
Asked Answered
R

1

5

Suppose I create a Wicket DropDownChoice containing a number of items.

Is it possible to display all items, but selectively disable one or more of them?

The only control you have over the appearance of the items is provided by IChoiceRenderer, but that only allows you to modify the text displayed for each item.

Recognizance answered 29/10, 2013 at 16:19 Comment(4)
How would you like the disabled choices to behave on the UI?Wichern
I would like them to be visible, but not selectable by the userRecognizance
Is the <optgroup> tag an option for you: w3schools.com/tags/tag_optgroup.asp ?Wichern
Thanks for your suggestions, however the proposed answer below works perfectly for me.Recognizance
J
7

A short search on the question returned this: http://apache-wicket.1842946.n4.nabble.com/disable-a-DropdownChoice-item-td1893424.html which seems to work for the user.

The solution was overriding the following method found in the AbstractChoice class from which DropdownChoice inherits

protected boolean isDisabled(final E object, int index, String selected)
 {
     return false;
 }

Another project that might be worth checking out is Select2 (http://ivaynberg.github.io/select2/) which features great selection tools but does not support disabling single options as far as i know.

Janijania answered 29/10, 2013 at 17:10 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.