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

Show all values #136

Closed
tomickigrzegorz opened this issue Mar 10, 2022 · 1 comment
Closed

Show all values #136

tomickigrzegorz opened this issue Mar 10, 2022 · 1 comment
Assignees
Labels
bug Something isn't working

Comments

@tomickigrzegorz
Copy link
Owner

The problem only occurs when we want to show all the results after clicking on the input field, and exactly when something is already selected or when there are no results.

Click on the input field for the first time. The results appear all and everything is fine. Then select a field by clicking on it. The data is saved in the input field.
Now I click on the input field again. And it is at this stage that this problem occurs. Because instead of displaying only one record, all data appears for a fraction of a second and then only this one record appears.

@tomickigrzegorz tomickigrzegorz self-assigned this Mar 10, 2022
@tomickigrzegorz tomickigrzegorz added the bug Something isn't working label Mar 10, 2022
tomickigrzegorz added a commit that referenced this issue Mar 10, 2022
@tomickigrzegorz
Copy link
Owner Author

tomickigrzegorz commented Mar 10, 2022

One more error found?
It's exactly about the destroy() method.

Sample code not entirely working properly:

const test = new Autocomplete("basic", {
  onSearch: ({ currentValue }) => {
    const api = `https://breakingbadapi.com/api/characters?name=${encodeURI(
      currentValue
    )}`;
    return new Promise((resolve) => {
      fetch(api)
        .then((response) => response.json())
        .then((data) => {
          resolve(data);
        })
        .catch((error) => {
          console.error(error);
        });
    });
  },

  onResults: ({ matches }) =>
    matches.map((el) => `<li>${el.name}</li>`).join(""),

  onSubmit: () => {
    test.destroy(); // issue
  },
});

When we have a button that clears the data x, the destroy() method does not hide the button, does not add a .hidden class to the button.

EDIT
This problem occurs when the destroy() method is called on onSubmit()
When the destroy method was called, e.g. as in the Complex example, everything works fine.

A quick workaround for this is setting:

onSubmit: () => {
  setTimeout(() => {
    test.destroy();
  }, 100);
},

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant