4

In Dojo, How to check that the button is already clicked or not. Here I need to do different task if button is clicked. For that I am using the following piece of code, but it is not working:

<form data-dojo-type="dijit/form/Form"
    data-dojo-id="customerIdSelector" id="customerIdSelector"
    method="post" action="/ritl/chart/iCustomerBaseEntryBarChart.htm">
  <table >
        ===========
         // Other components
        ===========

      <button data-dojo-type="dijit/form/Button" id="buttonOne" type="n">
          <div class="ri-ok">Generate Graph</div>
          <script type="dojo/method" data-dojo-event="onClick"data-dojo-args="evt">
     </button>
      if(buttonOne.onClick == true)
//    if(event.type == onClick)
           { 
               alert('onclick');                 
               functionToCall();
           }
      else  {
                alert('not clicked');
                return false;
            }
     ===========
   </table>
</form>

inside if(), what condition should be passed to check click event?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Tarun Chaudhary
  • 1,046
  • 2
  • 12
  • 20
  • You mean to see if the button has already been clicked once? If that is what you are after, you will need wither a global scoped js variable or an element on the page that you set when the button is clicked that you can check each time the button is clicked. – Maess Dec 12 '13 at 13:46
  • That could be an alternate solution for all, but in Dojo what condition to be there inside if() to check that. – Tarun Chaudhary Dec 12 '13 at 13:55
  • 2
    None... a button is stateless. So to save some state you will have to introduce that state (as a global scoped variable like @Maess said). If you really want a stateful button, you should look at a ToggleButton (http://dojotoolkit.org/reference-guide/1.9/dijit/form/ToggleButton.html). – g00glen00b Dec 12 '13 at 15:13

1 Answers1

1

I am answering to affirm Dimitri's response in the OP's question. A Button Dijit is stateless so you would need a global variable or an element in the DOM to hold the state. However, you could just use a toggle button

You can get it's state by using dijit/registry: registry.byId('buttonOne').get('checked')

drew
  • 86
  • 3