3

I have a simple form with selectOneMenu and textarea that I want to disable if certain value is chosen in the select (onchange event). How can I achieve this?

<p:selectOneMenu id="way" value="" onchange="">
    <f:selectItem value="0" itemLabel="#{texts.post}" />
    <f:selectItem value="1" itemLabel="#{texts.pickup}" />
</p:selectOneMenu>

<h:outputLabel for="address" value="#{texts.address}" />
<p:inputTextarea id="address" widgetVar="addressTextarea" value="" />
Nathan Kreider
  • 516
  • 3
  • 7
  • 16
Erveron
  • 1,908
  • 2
  • 25
  • 48

2 Answers2

4

I don't think there is an open interface to do so for inputTextarea but you could get the clientId and disable the html textarea or use jquery to disable it completely:

<p:selectOneMenu onchange="if(this.value == 1) { $(addressTextarea.input.attr('disabled', 'true)); $(addressTextarea.input.addClass('ui-state-disabled')) }">

Or using ajax you could use:

<p:selectOneMenu id="way" value="#{selectValue}">
    <f:selectItem value="0" itemLabel="#{texts.post}" />
    <p:ajax event="change" update="address"/>
</p:selectOneMenu>

<p:inputTextarea id="address" widgetVar="addressTextarea" value="" disabled="#{selectValue == 0}"/>
djmj
  • 5,579
  • 5
  • 54
  • 92
1

You can try this:

<p:inputTextarea id="address" widgetVar="addressTextareaWV" />

<p:selectOneMenu id="way" onchange="disableComponent()"/>

<script language="javascript" type="text/javascript">
    function disableComponent() {
        PF('addressTextareaWV').disable();
    }

    function enableComponent() {
        PF('addressTextareaWV').enable();
    }
</script>
John Alexander Betts
  • 4,718
  • 8
  • 47
  • 72