2 Replies Latest reply on Oct 5, 2007 11:12 AM by hdmonty

    How can I disable a commandButton, depends on f: validation?

    hdmonty

      Hello,

      In several situation I have the problem, that I can validate an input and show this in a message, but how can I disable/enable a commanButton.



      <h:inputText ...id="myInput" ... >
      <f:validateLength maximum="3" />
      </h:inputText>
      ...
      <rich:message for="tanowner" ... >
      <f:facet name="errorMarker">
      <h:graphicImage value="/images/error.gif" /> </f:facet>
      </rich:messge>
      ...
      <a4j:commandButton id="myButton" disable="???????" ...
      </a4j:commandButton>



      How can I manage this?
      Thx

        • 1. Re: How can I disable a commandButton, depends on f: validat
          ilya_shaikovsky

          I ve used

          <h:form id="form">
           <script>
           function checkMessages(){
           if (document.getElementById('form:messages')==null){
           document.getElementById('form:button').disabled=false;
           }
           else{
           document.getElementById('form:button').disabled=true;
           }
          
           }
           </script>
           <h:inputText value="#{bean.property1}" required="true">
           <f:validateLength minimum="3" maximum="5"/>
           <a4j:support event="onkeyup" bypassUpdates="true" ajaxSingle="true" oncomplete="checkMessages();"/>
           </h:inputText>
           <a4j:outputPanel ajaxRendered="true">
           <h:messages id="messages"/>
           </a4j:outputPanel>
           <a4j:commandButton value="Press me!" id="button"/>
           </h:form>
          


          For such functionality.. Unfortunatelly I'm failed to use rich:messages - because to be ajax updatable they always generate span with messages id ://

          • 2. Re: How can I disable a commandButton, depends on f: validat
            hdmonty

            Thank you very much, it works fine.