Skip to content

Commit

Permalink
Fixed #11526 - Dropdown value not set properly when options come late…
Browse files Browse the repository at this point in the history
…r than value
  • Loading branch information
mertsincan committed May 23, 2022
1 parent 8d42ecc commit d2c3db6
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/app/components/dropdown/dropdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,13 @@ export class Dropdown implements OnInit,AfterViewInit,AfterContentInit,AfterView
this._options = val;
this.optionsToDisplay = this._options;
this.updateSelectedOption(this.value);

this.selectedOption = this.findOption(this.value, this.optionsToDisplay);
if (!this.selectedOption) {
this.value = null;
this.onModelChange(this.value);
}

this.optionsChanged = true;

if (this._filterValue && this._filterValue.length) {
Expand Down Expand Up @@ -604,10 +611,6 @@ export class Dropdown implements OnInit,AfterViewInit,AfterContentInit,AfterView
this.value = this.getOptionValue(this.selectedOption);
this.onModelChange(this.value);
}
else if (!this.selectedOption) {
this.value = null;
this.onModelChange(this.value);
}

this.selectedOptionUpdated = true;
}
Expand Down

4 comments on commit d2c3db6

@LucasBortolazzo
Copy link

@LucasBortolazzo LucasBortolazzo commented on d2c3db6 May 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @mertsincan ,
There seems to be a problem with this implementation. When the formcontrol linked to the p-dropdown has a null value, the lines "this.value = null and this.onModelChange(this.value)" are improperly executed, triggering a "valueChanges" event (changing the value to null) of the formControl and marking it as dirty improperly.
Please see the second comment of this thread: ed3b308.

To resolve this, we had to temporarily revert to version 13.3.3.

Regards

@mertsincan
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @LucasBortolazzo,

Thanks a lot for the feedback! Could you please attach a sample stackblitz link for us to replicate?

@LucasBortolazzo
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @mertsincan ,
yes.. I'll try to reproduce it in a new application and then I'll send the stackblitz link.

Thanks.

@Menecats
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, this behaviour is currently tracked by the issue #11559

Please sign in to comment.