[英]Disable JSF Primefaces textArea on event
I have a simple form with selectOneMenu and textarea that I want to disable if certain value is chosen in the select (onchange event). 我有一个带selectOneMenu和textarea的简单表单,如果在select(onchange事件)中选择了某个值,我想禁用它。 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 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: 我不认为有一个开放的接口来为inputTextarea这样做,但你可以获取clientId并禁用html textarea或使用jquery完全禁用它:
<p:selectOneMenu onchange="if(this.value == 1) { $(addressTextarea.input.attr('disabled', 'true)); $(addressTextarea.input.addClass('ui-state-disabled')) }">
Or using ajax you could use: 或者使用ajax你可以使用:
<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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.