Reputation: 951
I have a checkbox asking if someone is an adult. Then I have 2 inputs. The problem is how to, after changing the checkbox value, alter the required property of the inputs. I am updating the whole form, and it works. Is there a better way to do that? Second, is there a way to do it all on client side?
<p:selectBooleanCheckbox id="adultCheckbox" value="#{bean.adult}">
<p:ajax update="@form"/>
</p:selectBooleanCheckbox>
<p:inputText id="property1" value="#{bean.property1}"
required="#{bean.adult eq true }"/>
<p:inputText id="property2" value="#{bean.property2}"
required="#{bean.adult eq true }"/>
Upvotes: 0
Views: 785
Reputation: 4423
You can do it a little bit better:
<p:selectBooleanCheckbox id="adultCheckbox" value="#{bean.adult}">
<p:ajax update="property1, property2"/>
</p:selectBooleanCheckbox>
<p:inputText id="property1" value="#{bean.property1}"
required="#{bean.adult}"/>
<p:inputText id="property2" value="#{bean.property2}"
required="#{bean.adult}"/>
You could do something on client side customizing the Client Side Validation as described here. Buy I still believe is a good idea to do that through a Ajax Request.
Upvotes: 1