setValue() does not work for nb-select component
See original GitHub issueIssue type
I’m submitting a … (check one with “x”)
- bug report
- feature request
Issue description
Current behavior:
Setting the value of nb-select
programmatically sets the value on Reactive Form control but nb-select
does not display it.
Expected behavior:
nb-select
displays the value set programmatically.
Steps to reproduce:
- Create Reactive Form
- Add
nb-select
to the form - Set object value to the
-nb-select
Related code:
<form [formGroup]="form">
<nb-select formControlName="user">
<nb-option *ngFor="let u of users" [value]="u">{{u.name}}</nb-option>
</nb-select>
</form>
this.form = this.fb.group({
user: ['']
});
this.form.get('user').setValue({ name: 'Maihan', age: 55, gender: 'Male' });
this.form.controls['user'].patchValue(
{ name: 'Maihan', age: 55, gender: 'Male' }
)
StackBlitz StackBlitz Seed Project
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:5 (2 by maintainers)
Top Results From Across the Web
Formbuilder setvalue() is not working as expected when used ...
I expect the corresponding dropdown option to be selected when I pass the value to the setValue() . Instead, I get a blank...
Read more >Select setValue does not work as documented and as expected
The setValue method of the Select component does what the documentation says and sets the value of the Select to the given string...
Read more >setValue on Textarea/Select Components from Event Handler ...
Hey guys, To explain the problem I'm seeing, I'm using the retool on-premise version 2.80.16 and I am attaching event handers to set...
Read more >Dropdownlist reactive form setValue not working - EJ 2 Forums
I'm having a problem assigning a value to a reactive form control dropdownlist. Value is not set. Form definition: private defineForm() {.
Read more >API - React Select
Even when commonProps are not listed in the prop types below, a custom component will still have access to them. StateManager Props. The...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Try with this setTimeout(): function.
Hi @maihannijat, from my point of view, nb-select works as expected. Regarding the setValue(), as I see it, you’re providing values for nb-option’s as references to objects from users array. And then, passing the different object with different reference to the setValue() method. nb-select internally compares items by reference using plain === operator. So, in your case, please, pass user’s id’s as values to nb-option’s like that one:
and then call setValue() with the appropriate user.id.
Or just pass the same user object like so:
Regarding the reset method. As I see it, it’s a private method of nb-select. And when it’s used internally, nb-select also calls markForCheck() after the call. So, you have to mark the component as dirty after calling that method. By the way, I don’t think you have to use it 😃