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.96k stars 1.24k forks source link

MultiComboBox not updated after change of selectedKeys #3779

Closed BastianKanaan closed 1 year ago

BastianKanaan commented 1 year ago

OpenUI5 version: 1.108.6

Browser/version (+device/version): Firefox 113.0.2 (64-Bit)

Any other tested browsers/devices(OK/FAIL): -/-

URL (minimal example if possible): https://jsbin.com/guyubij/2/edit?html,output

User/password (if required and possible - do not post any confidential information here): -/-

Steps to reproduce the problem:

  1. Click the button in the example above

What is the expected result? Selected keys in MultiComboBox updated (value "B" is added to the bound model)

What happens instead? MultiComboBox stays same

Any other information? (attach screenshot if possible)

stopcoder commented 1 year ago

Hi @BastianKanaan,

this is caused by the difference between property binding and aggregation binding. The selectedKeys is a property of MultiComboBox and its bound data is the array that is set to keys property in the model. After you call data.keys.push, the array itself doesn't change, which is still the same reference, although its content is changed. Therefore the MultiComboBox doesn't receive an update for the selectedKeys property. You can use data.keys = ["A", "B"]; to change the array to another reference and the change detection will take this as a change for the property binding. The control will then react to it.

Best regards, Jiawei SAPUI5 Core Dispatcher

BastianKanaan commented 1 year ago

Hello @stopcoder , thanks for your reply. Can you point to a piece of documentation where this is explained? I would like to read a hint in the API reference. A sample for proper two-way-binding could also help.

I extended my example to [https://jsbin.com/guyubij/6/edit?html,console,output]() . The Button "[2]" now works. It does the suggested data.keys = ["A", "B"];. But Button "[3]" will not work. It adds priorly the value B. So the reference is changed, but the content stays same regarding just the assignment.