title: Changing function on a button using detachPress / attachPress
body: <p>I have a requirement for my app and I need to change the event handler of a common button depending on the status of the workflow. </p>
  
  <p>Basically I need to change the function called when you press the button and vice-versa and was looking to achieve this by using the event handler functions <strong>detachPress</strong> and <strong>attachPress</strong>.</p>
  
  <p><a href="https://ui5.sap.com/#/api/sap.m.Button/methods/detachPress" rel="nofollow noreferrer">https://ui5.sap.com/#/api/sap.m.Button/methods/detachPress</a>
  <a href="https://ui5.sap.com/#/api/sap.m.Button/methods/attachPress" rel="nofollow noreferrer">https://ui5.sap.com/#/api/sap.m.Button/methods/attachPress</a></p>
  
  <p>My Button (XML View):</p>
  
  <pre><code>&lt;Button text="Edit" width="50%" id="_editButtonEmail" press="editPIN"/&gt;
  </code></pre>
  
  <p>On my controller I want to change the function <strong>editPIN</strong> by <strong>cancelEditPIN</strong>.</p>
  
  <p>Some things I've tried:</p>
  
  <pre><code>    editPIN: function(oControlEvent) {
         //change button
         var editButton = this.getView().byId("_editButtonEmail");
         //detach this function on press
         editButton.detachPress(editButton.mEventRegistry.press[0].fFunction);
         editButton.attachPress(this.cancelEditPIN());
      }
  
      cancelEditPIN: function() {
         //do something else
      }
  </code></pre>
  
  <p>Also</p>
  
  <pre><code>editPIN: function(oControlEvent) {
     //change button
     var src = oControlEvent.getSource();
     src.detachPress(this.editPIN());
     src.attachPress(this.cancelEditPIN());
  }
  </code></pre>
  
  <p>None of these seem to work and if I check my console the function <strong>editPIN</strong> is still attached to my <strong>mEventRegistry</strong> press event.</p>
  
  <p><a href="https://i.stack.imgur.com/BOFYK.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/BOFYK.jpg" alt="enter image description here"></a></p>