How can I have the first item in a listbox disabled? Following is my code:
ListBox list = new ListBox();
list.addItem("Select an item");
list.addItem("a");
list.addItem("b");
list.addItem("c");
How do I disable the first item in list? Thanks so much
list.getElement().<SelectElement>cast().getOptions().getItem(0).setDisabled(true);
For anyone who finds this page and is looking to disable a GWT ListBox option which is NOT the first option in the ListBox, this worked for me:
list.getElement().getElementsByTagName("option").getItem(itemNumber).setAttribute("disabled", "disabled");
Where itemNumber is the option you would like to disable.
You could select the first child element and set the disabled atribute:
list.getElement().getFirstChildElement().setAttribute("disabled", "disabled");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With