-
Notifications
You must be signed in to change notification settings - Fork 161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(combo, simple-combo): filter out non-existent items from selection - master #14772
base: master
Are you sure you want to change the base?
Conversation
projects/igniteui-angular/src/lib/combo/combo.component.spec.ts
Outdated
Show resolved
Hide resolved
projects/igniteui-angular/src/lib/combo/combo.component.spec.ts
Outdated
Show resolved
Hide resolved
projects/igniteui-angular/src/lib/combo/combo.component.spec.ts
Outdated
Show resolved
Hide resolved
projects/igniteui-angular/src/lib/combo/combo.component.spec.ts
Outdated
Show resolved
Hide resolved
projects/igniteui-angular/src/lib/combo/combo.component.spec.ts
Outdated
Show resolved
Hide resolved
projects/igniteui-angular/src/lib/combo/combo.component.spec.ts
Outdated
Show resolved
Hide resolved
projects/igniteui-angular/src/lib/combo/combo.component.spec.ts
Outdated
Show resolved
Hide resolved
projects/igniteui-angular/src/lib/combo/combo.component.spec.ts
Outdated
Show resolved
Hide resolved
projects/igniteui-angular/src/lib/combo/combo.component.spec.ts
Outdated
Show resolved
Hide resolved
Setting the selection via the |
@RivaIvanova @jackofdiamond5 Are you suggesting that the Please let me know if I’ve understood your suggestion correctly or if there’s another approach you’d prefer me to consider. |
You are correct and the <igx-combo
#comboModel
#myComboModel="ngModel"
required
[data]="items"
[(ngModel)]="ngModelValue"
>
<label igxLabel>Fruits</label>
</igx-combo>
combo selection {{ comboModel.selection.length }}
combo valid {{ myComboModel.valid }} public items: any[] = ['Mango', 'Banana', 'Apple'];
public ngModelValue = ['invalid value']; In this case, the combo selection is 0, and nothing is displayed in the read-only input field, which is correct according to the new changes. However, the controls If the custom The same is true if we have a combo inside a reactive form. <form [formGroup]="user">
<igx-combo
[data]="genres"
formControlName="genres"
>
<label igxLabel>Movies</label>
</igx-combo>
</form>
reactive form valid {{ user.valid }} public user: UntypedFormGroup;
public genres: any[] = ['Action', 'Comedy', 'Adventure'];
constructor(fb: UntypedFormBuilder) {
this.user = fb.group({
genres: [['test'], Validators.required],
});
} If we set Here is a sample that demonstrates the configuration. Also, this enhancement aligns the Angular combo with the WC one, which is great, but this should be addressed for the simple combo as well. 🙂 |
…into ganastasov/feat-14732-master
…into ganastasov/feat-14732-master
…into ganastasov/feat-14732-master
We have separated this behavior into a separate issue #14949 to ensure it is considered independently and does not block the new enhancement. The enhancement is already implemented and ready for review. |
@@ -2606,6 +2610,32 @@ describe('igxCombo', () => { | |||
expect(selectionSpy).toHaveBeenCalledWith(expectedResults); | |||
expect(input.nativeElement.value).toEqual(expectedDisplayText); | |||
}); | |||
it('should only select and display existing values in the data when programmatically selecting non existing items with ngModel', fakeAsync(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one directly modifies the value of the field bound to the model and the one below changes the value through an API call. So, we should change the tests' descriptions accordingly.
if (item !== undefined) { | ||
const newSelection = this.selectionService.add_items(this.id, item instanceof Array ? item : [item], true); | ||
this.setSelection(newSelection); | ||
if (item === undefined) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At this point the select
methods for both combos are very similar. So, it should be safe to extract the logic to a common method.
this._value = this.valueKey ? super.selection.map(item => item[this.valueKey]) : super.selection; | ||
this.filterValue = this._displayValue?.toString() || ''; | ||
this._value = value !== undefined ? [value] : []; | ||
this.setSelection(new Set(this._value), undefined, false, false); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we check if we also have the data loaded here, like we do with the other combo 🤔 In which case, it could be possible to have the writeValue
method cease being abstract in combo.common
as we could merge the logic of both methods into a common one.
Closes #14732
Additional information (check all that apply):
Checklist:
feature/README.MD
updates for the feature docsREADME.MD
CHANGELOG.MD
updates for newly added functionalityng update
migrations for the breaking changes (migrations guidelines)