1 Reply Latest reply on Sep 29, 2011 7:32 PM by iabughosh

    Disable button in modal

    ibstmt

      I have a command button on a modal panel. When the user clicks it, I want to disable it so that he doesn't click it twice. I found some code to do this, and it works:

       

      <a4j:commandButton value="OK"

          ajaxSingle="true" action="#{myBean.process}"

          onclick="this.disabled=true"

          oncomplete="#{rich:component('myModal')}.hide();">

       

      The problem is that, the next time I call this modal panel, the button is still disabled. I can't put the code to enable it in the 'oncomplete', because I need to hide the modal there (and I don't think you can specify two actions.)

       

      Is there a solution, or am I using a bad approach to this problem?

        • 1. Re: Disable button in modal
          iabughosh

          yes, you can use a4j:status for this sort of tasks:

           

          <a4j:commandButton id="testBtn"

               value="OK"

              ajaxSingle="true" action="#{myBean.process}"

              status="testStatus"

              oncomplete="#{rich:component('myModal')}.hide();">

           

          <a4j:status id="testStatus"

                           name="testStatus"

                           onstart="#{rich:element('testBtn')}.disabled=true;"

                           onstop="#{rich:element('testBtn')}.disabled=false;">                     

          </a4j:status>

           

          regards.