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

Fix "no choices to choose from"/"no results found" notice did not reliably trigger #1192

Merged
merged 6 commits into from
Sep 4, 2024

Conversation

Xon
Copy link
Collaborator

@Xon Xon commented Aug 31, 2024

No description provided.

@tagliala
Copy link
Contributor

tagliala commented Sep 1, 2024

Hi,

I'm testing this branch

It works better than the actual implementation, but there are still a few issues with "remote/dynamic" fields.

First issue: "no choices" appearing when it should not appear

I think it is related to some missing checks after setChoices

const select = document.querySelector("#choices");
const choices = new Choices(select, { noChoicesText: 'Hello World!' } );

choices.passedElement.element.addEventListener(
  'search',
  function (e) {
    choices.setChoices(
      [{ value: 'alice', label: 'Alice' }, { value: 'bob', label: 'Bob' }],
      'value',
      'label',
      true
    )
  }
)

v11: https://jsfiddle.net/tagliala/rx8mtbz6/17/

image

v10: https://jsfiddle.net/tagliala/rx8mtbz6/18/

image

Second issue: "no choices" having priority over "no results found".

It seems that "no choices" now have priority on "no results found".

const select = document.querySelector("#choices");
const choices = new Choices(select, { noChoicesText: 'Hello World!' } );

choices.passedElement.element.addEventListener(
  'search',
  function (e) {
    choices.setChoices(
      [],
      'value',
      'label',
      true
    )
  }
)

This can be seen as a legit behaviour change, but I think that v10 worked better, showing "no results found" when a query was present even if choices were empty

v11: https://jsfiddle.net/tagliala/rx8mtbz6/20/

image

v10: https://jsfiddle.net/tagliala/rx8mtbz6/22/

image

@Xon
Copy link
Collaborator Author

Xon commented Sep 2, 2024

@tagliala It looks like setChoices didn't clear the cached notice, so the last notice "stuck". That should be fixed.

I think the entire notice system needs a bit of a rework to avoid this ad-hoc matching and to be more centralized (basically making a notice reducer which listens for the relevant add/remove events.

But for now the current code should work

@tagliala
Copy link
Contributor

tagliala commented Sep 2, 2024

@Xon thanks, can you rebase this branch on master? I would like to take a look

@Xon
Copy link
Collaborator Author

Xon commented Sep 2, 2024

Should be rebased now

@Xon Xon marked this pull request as ready for review September 4, 2024 11:06
@Xon Xon changed the title Better handle no selectable choices Fix regression "no choices to choose from"/"no results found" notice did not reliably trigger Sep 4, 2024
@Xon Xon added bugfix Pull request that fixes an existing bug and removed bug labels Sep 4, 2024
@Xon Xon merged commit 3d79892 into main Sep 4, 2024
9 checks passed
@Xon Xon deleted the fix-display-banner branch September 4, 2024 11:29
@Xon Xon changed the title Fix regression "no choices to choose from"/"no results found" notice did not reliably trigger Fix "no choices to choose from"/"no results found" notice did not reliably trigger Sep 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix Pull request that fixes an existing bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[v11] main branch: Regression in "no choices text" when clearing search field
2 participants