Skip to content
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

Open
wants to merge 27 commits into
base: master
Choose a base branch
from

Conversation

georgianastasov
Copy link
Contributor

@georgianastasov georgianastasov commented Sep 16, 2024

Closes #14732

Additional information (check all that apply):

  • Bug fix
  • New functionality
  • Documentation
  • Demos
  • CI/CD

Checklist:

  • All relevant tags have been applied to this PR
  • This PR includes unit tests covering all the new code (test guidelines)
  • This PR includes API docs for newly added methods/properties (api docs guidelines)
  • This PR includes feature/README.MD updates for the feature docs
  • This PR includes general feature table updates in the root README.MD
  • This PR includes CHANGELOG.MD updates for newly added functionality
  • This PR contains breaking changes
  • This PR includes ng update migrations for the breaking changes (migrations guidelines)
  • This PR includes behavioral changes and the feature specification has been updated with them

@RivaIvanova RivaIvanova added 💥 status: in-test PRs currently being tested and removed ❌ status: awaiting-test PRs awaiting manual verification 💥 status: in-test PRs currently being tested labels Oct 8, 2024
@RivaIvanova
Copy link
Member

Setting the selection via the select method emits the selectionChanging event. It does not matter if it is a valid selection or not. The event should be emitted only on user interaction.

@RivaIvanova RivaIvanova added the 🛠️ status: in-development Issues and PRs with active development on them label Oct 8, 2024
@georgianastasov
Copy link
Contributor Author

Setting the selection via the select method emits the selectionChanging event. It does not matter if it is a valid selection or not. The event should be emitted only on user interaction.

@RivaIvanova @jackofdiamond5
Currently, the select() method emits the selectionChanging event even when the selection is set programmatically, regardless of whether the selection is valid.

Are you suggesting that the selectionChanging event should only be emitted on user interactions and not when the selection is changed programmatically via the select() method? If so, would you like me to modify the select() method to prevent it from emitting this event during programmatic changes?

Please let me know if I’ve understood your suggestion correctly or if there’s another approach you’d prefer me to consider.

@RivaIvanova RivaIvanova added 💥 status: in-test PRs currently being tested and removed 🛠️ status: in-development Issues and PRs with active development on them labels Oct 9, 2024
@RivaIvanova
Copy link
Member

You are correct and the select method along with the selectAllItems, setSelectedItem, deselect, deselectAllItems methods emit the selectionChanging event prior to this PR so you can disregard the previous comment. However, there are some other behaviors that I observed when the combo has the required attribute set:

<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 valid property is true but should be false.

If the custom ngModelValue is set to an empty array, i.e., public ngModelValue = [];, the valid property is properly set to false.

igxCombo - required

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 genres to an empty array genres: [[], Validators.required], the reactive form's valid property is false.

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. 🙂

@RivaIvanova RivaIvanova added 🛠️ status: in-development Issues and PRs with active development on them and removed 💥 status: in-test PRs currently being tested labels Oct 9, 2024
@georgianastasov georgianastasov changed the title feat(combo): filter out non-existent items from selection - master feat(combo, simple-combo): filter out non-existent items from selection - master Oct 9, 2024
@georgianastasov
Copy link
Contributor Author

georgianastasov commented Oct 25, 2024

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.

@georgianastasov georgianastasov added ❌ status: awaiting-test PRs awaiting manual verification and removed 🛠️ status: in-development Issues and PRs with active development on them labels Oct 25, 2024
@RivaIvanova RivaIvanova added 💥 status: in-test PRs currently being tested and removed ❌ status: awaiting-test PRs awaiting manual verification labels Oct 25, 2024
@RivaIvanova RivaIvanova added ✅ status: verified Applies to PRs that have passed manual verification and removed 💥 status: in-test PRs currently being tested labels Oct 25, 2024
@@ -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(() => {
Copy link
Member

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) {
Copy link
Member

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);
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
combo version: 19.0.x ✅ status: verified Applies to PRs that have passed manual verification
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Mismatch in combo/simple-combo: Non-matching values should not appear in the selection
4 participants