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="" />
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="" />
Share
Improve this question
edited Mar 11, 2012 at 2:12
Nathan Kreider
5163 gold badges7 silver badges16 bronze badges
asked Mar 11, 2012 at 1:02
ErveronErveron
1,9282 gold badges25 silver badges48 bronze badges
2 Answers
Reset to default 4I 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 pletely:
<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}"/>
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>