cancel
Showing results for 
Search instead for 
Did you mean: 

Does any method to listen the control's binding model change or property change?

Former Member
0 Kudos

Hi Team,

Now I have a checkbox control and I want to do some action when it's property 'selected' is changed. It is binding with the model. Is there any method to listen the property change or binding model change? I saw there is 'attachModelContextChnage' method but after trying it doesn't work and I am not clear about its usage.

Thanks,

Mengchi     

Accepted Solutions (1)

Accepted Solutions (1)

saivellanki
Active Contributor
0 Kudos

Hi Mengchi,

Can you try something like this:

For example, if it is 'selected' property:


var oCheckBox = this.getView().byId("oCheckBox");

var oSelectedBinding = oCheckBox.getBinding("selected");

oSelectedBinding.attachChange(function(){

     //your logic

});

Regards,

Sai.

Former Member
0 Kudos

Thanks for your help. It works!

And could I get the checkbox control through the binding property?

Thanks,

Mengchi

Answers (2)

Answers (2)

former_member182862
Active Contributor
0 Kudos

Hi Mengchi

Would overriding the setProperty of checkbox help?

JS Bin - Collaborative JavaScript Debugging

Former Member
0 Kudos

Hi Mengchi ..

I thinnk you might be using sap.m.chekcbox ...if yes than there is an event "select" which will be raised when you change the property selected ... check below

SAPUI5 Explored

thanks

viplove

Former Member
0 Kudos

Hi Viplove,

Thanks for your reply. Yes, I use sap.m.checkbox. But its selected property will be change by binding model change which is changed by other control, so the event 'select' cannot catch it.

Thanks,

Menghchi

Former Member
0 Kudos

Hi Mengchi  ,


Oh .. thats the issue .... one thing you can do is before refreshing the model capture the checkbox value and after refreshing capture its value again and compare..if the value changes you can do your action ...


If you can tell when and how you are changing the checkbox value ... and what action you want to perform


thanks

Viplove ..

suresu22
Explorer
0 Kudos

Hi Menghchi,

try to use modelContextChange event



thanks

Suresh

Former Member
0 Kudos

Hi Suresh,

I try to use modelContextChange event While it doesn't work when the binding property is changed. So whether this event will be called when the binding model changes rather than binding data changes?

Thanks,

Mengchi

Former Member
0 Kudos

Hi Mengchi ,

Actually you can get the property binding of the check box and than attach the change event to the property binding retrieved ...

Reference :

property binding : JsDoc Report - SAP UI development Toolkit for HTML5 - API Reference - sap.ui.model.PropertyBinding

issue : sap.ui.model.Binding attachChange is always fired regardless of the sPath and context of binding · I...

thanks

Viplove