SAP / openui5

OpenUI5 lets you build enterprise-ready web applications, responsive to all devices, running on almost any browser of your choice.
http://openui5.org
Apache License 2.0
2.92k stars 1.23k forks source link

Model event propagation does not work as expected #4006

Closed slavik-lvovsky closed 4 months ago

slavik-lvovsky commented 4 months ago

OpenUI5 version: 1.108.26

Browser/version (+device/version): any browser

Snippet: #804290

Steps to reproduce the problem:

  1. Change the Purpose item
  2. The checkbox should be disabled

What is the expected result?

The "Purpose" model event handler for "/purpose/selectedKey" sets a new value for the "AuthGrant" model at "/authGrant/selectedKey". This action, in turn, triggers a model event that reaches the event handler for "/authGrant/selectedKey", resulting in a change to the "/checkbox/enabled" property.

What happens instead?

When "/authGrant/selectedKey" is changed by either oModel.setProperty("/authGrant/selectedKey", sNewAuthGrantSelectedKey); line 61 or oModel.setProperty("/authGrant/selectedKey", sNewAuthGrantSelectedKey, undefined, true); line 62 the event does not reach the "/authGrant/selectedKey" handler.

The event only triggers when "/authGrant/selectedKey" is changed by directly using the AuthGrant select control. lines 63-64

It seems that when a model event change handler triggers another model property change, the second event does not propagate and disappears.

TeodorTaushanov commented 4 months ago

Hello,

It seems the issue is in "isModelPropertyChanged" method.

I modified your snippix to #450486

oModel.attachPropertyChange(oEvent => {                 
                    oModel.setProperty("/checkbox/enabled", oModel.getProperty("/authGrant/selectedKey") === 'AuthGrant 1');                    
                });

and it is working correctly.

Best, Teodor

slavik-lvovsky commented 4 months ago

Hi @TeodorTaushanov,

I understand what you did in the #450486, but your logic just hides the bug. You can put a breakpoint in the oModel.attachPropertyChange(oEvent you have created and see that no event comes from changing the "/authGrant/selectedKey" property. All events come only from changing the "/purpose/selectedKey" property.

Please reopen the issue and investigate it.

Regards, Slavik.

TeodorTaushanov commented 4 months ago

I've created an internal incident DINC0097996. The status of the issue will be updated here in GitHub.

Regards, Teodor

boghyon commented 4 months ago

From the issue description:

When "/authGrant/selectedKey" is changed by either oModel.setProperty ...

According to the description of the propertyChange event:

Currently the event is only fired with reason sap.ui.model.ChangeReason.Binding which is fired when two way changes occur to a value of a property binding.

A two way change occurs when the value change is triggered from the UI. I.e. a change via the Model#setProperty (one way) won't fire the propertyChange event. It works as expected.

boghyon commented 4 months ago

Duplicate of https://github.com/SAP/openui5/issues/2430

slavik-lvovsky commented 4 months ago

Hi @boghyon , @TeodorTaushanov , @i556484 ,

Thank you for investigating the issue. Does it mean that for now, the only solution for me is to use the sap.mSelect (AuthGrant) control's setSelectedKey method instead of the oModel.setProperty method?

Regards, Slavik.