Topic: Dynamic selects with reactive forms don't retain value

josh.novak pro asked 5 years ago


I have a reactive form and I load the data for the form onInit. After that I load the data for the selects, but the select does not retain the value I gave it initially. For example if the value should be 46 and I then load all the values, it doesn't load the option with value 46, it just does nothing. I found a temp work around, but it's very hacky. There should be a better way to handle this.

Arkadiusz Idzikowski staff answered 5 years ago


Dear josh.novak, I checked it and I see that there are some problems with setting preselected value after select options were updated dynamically that we need to fix. Is that what you tried to achieve? Update select options and then set new preselected value? Could you please write something more about your fix and the behavior you expected from the component in this situation? Best, Arek

josh.novak pro commented 5 years ago

Yeah the Issue is if I set the value using patchValue and then add options to the select it does not show the correct value. The temp fix was to patch the value into the form again manually. I ended up switch all the selects to use ng-select since that select works properly and adds tagging etc.

Arkadiusz Idzikowski staff commented 5 years ago

This problem will be fixed in next release.


Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Answered

Specification of the issue

  • ForumUser: Pro
  • Premium support: No
  • Technology: MDB Angular
  • MDB Version: -
  • Device: -
  • Browser: -
  • OS: -
  • Provided sample code: No
  • Provided link: No
Tags