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. 

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 **detachPress** and **attachPress**.

<https://ui5.sap.com/#/api/sap.m.Button/methods/detachPress>
<https://ui5.sap.com/#/api/sap.m.Button/methods/attachPress>

My Button (XML View):

```
<Button text="Edit" width="50%" id="_editButtonEmail" press="editPIN"/>

```

On my controller I want to change the function **editPIN** by **cancelEditPIN**.

Some things I've tried:

```
    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
    }

```

Also

```
editPIN: function(oControlEvent) {
   //change button
   var src = oControlEvent.getSource();
   src.detachPress(this.editPIN());
   src.attachPress(this.cancelEditPIN());
}

```

None of these seem to work and if I check my console the function **editPIN** is still attached to my **mEventRegistry** press event.

[![enter image description here](https://i.stack.imgur.com/BOFYK.jpg)](https://i.stack.imgur.com/BOFYK.jpg)