0

MVVM Combobox selectedItem reset

asked 2019-01-04 18:01:54 +0800

gaiol gravatar image gaiol
20 2
http://www.bgserviceit.be

Hello,

I have a problem while reseting or refreshing a selected item in a combobox.

Here is the Fiddle : http://zkfiddle.org/sample/h20l03/68-reset-combobox-MVVM

To reproduce : - run the fiddle - choose the element in combobox - click on reset, the combobox content should be deleted - if it works, it will always on the same run, so, close the window and run again...

Sometimes, the combobox's content is deleted, sometimes it is not, it seems random. I tried with the NotifyChange annotation, same result. I'm on google chrome 70.0.3538.77. Thanks for your help and sorry for my bad english.

delete flag offensive retag edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2019-01-07 10:57:34 +0800

cor3000 gravatar image cor3000
6280 2 7

updated 2019-01-07 10:57:54 +0800

I am not fully sure why your scenario behaves non deterministic, I assume it has to do with the notify change "*". When using a ListModelList there's no need to replace the model, just clear and refill it (it will update the combobox content automatically), then things get a lot simpler and the problem didn't happen anymore.

e.g.: http://zkfiddle.org/sample/h20l03/71-reset-combobox-MVVM

Besides you don't need to bind the property selectedSearchedOrg to selectedItem. The ListModelList will keep track of selections automatically for you. You can retrieve it by calling searchedOrgs.getSelection(). Keeping duplicate state can often lead to synchronization issues. Only relying on a single source makes cleanup much simpler.

see this updated example: http://zkfiddle.org/sample/h20l03/72-reset-combobox-MVVM

It takes advantage of ListModelList keeping track of the selection, and only if the selection is changed you can update your own model property, or decide to keep it. Another benefit is that you only expose getters to the UI, making it easier to reason about the data flow.

link publish delete flag offensive edit

Comments

Big thanks ! Very complete and useful answer.

gaiol ( 2019-01-07 17:07:22 +0800 )edit
Your answer
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow
3 followers

RSS

Stats

Asked: 2019-01-04 18:01:54 +0800

Seen: 22 times

Last updated: Jan 07 '19

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More