4

How can I make the <h:selectOneMenu> dropdown list unselectable?

It is not like using disabled. I just want to make the dropdown list options unselectable and to appear with a different (inactive) style class.

How can I achieve this? By a JSF component attribute or CSS or JavaScript?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
AKZap
  • 1,181
  • 6
  • 17
  • 31
  • What do you mean with "unchangeable/unselectable"? That nothing happens when clicking on it (no drop down) or that selecting a value doesn't let it show up, or that it has no effect when submitting? – Zeemee Apr 30 '12 at 05:28
  • @Mulmoth "unchangeable/unselectable" mean that nothing happens when clicking on it (no drop down). – AKZap Apr 30 '12 at 05:37
  • Then the disabled attribute is the only option. – Zeemee Apr 30 '12 at 05:57

3 Answers3

15
<asp:DropDownList ID="ddlName" runat="server" style="pointer-events: none; cursor: default;">
</asp:DropDownList>

Add style attribute to DropDownList as style="pointer-events: none; cursor: default;". This will work succesfully, I have tried this.

Jeroen
  • 60,696
  • 40
  • 206
  • 339
SanamShaikh
  • 1,699
  • 3
  • 13
  • 22
  • 2
    with jQuery: $('#DropdownID').css({"pointer-events": "none", "cursor": "default"}); – Hugo Jul 28 '13 at 10:30
3

If I understand you correctly, all you need to do is use the disabled attribute.

So, if you have a select tag like this:

<select>
  <option>Value</option>
  <option>Value</option>
  <option>Value</option>
</select>

Simply change it to this:

<select disabled>
  <option>Value</option>
  <option>Value</option>
  <option>Value</option>
</select>

Some doctypes require all attributes to have values, in order to be valid. In that case, you can just use disabled="true" instead.

Ryan
  • 3,726
  • 3
  • 26
  • 38
1

According to this answer, some browsers allow to change the style of disabled components (non-IE), some not (IE). However, the answer is 3 years old - a long time for browsers. So you could try a solution like:

<h:selectOneMenu disabled="true" style="..." ...>

... and check the result with different browsers.

Or alternatively use the readonly attribute:

<h:selectOneMenu readonly="true" style="..." ...>
Community
  • 1
  • 1
Matt Handy
  • 29,855
  • 2
  • 89
  • 112