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

Autocomplete share "onOptionClick" for multiple instances #93

Closed
bugy opened this issue Mar 24, 2021 · 0 comments · Fixed by #94
Closed

Autocomplete share "onOptionClick" for multiple instances #93

bugy opened this issue Mar 24, 2021 · 0 comments · Fixed by #94
Labels

Comments

@bugy
Copy link

bugy commented Mar 24, 2021

Bug description

If you add multiple autocomplete components on a page, their "onOptionClick" handlers are somehow interdependent
Here is an example (I just select options from 3 autocomplete in a row):
autocompletes_bug

Codewise: in autocomplete.js there is the following code:

      let dropdownOptions = $.extend(
        Autocomplete.defaults.dropdownOptions,
        this.options.dropdownOptions
      );

So on every init we extend default options with new dropdown options. I.e. we modify defaults every time we create a new autocomplete.

This was introduced in #60

Steps to Reproduce

Create 3 autocomplete, like this:

      <div class="input-field">
        <input id="autocomplete-input" class="autocomplete" type="text">
        <label for="autocomplete-input">Autocomplete</label>
      </div>

      <div class="input-field">
        <input id="autocomplete-input2" class="autocomplete" type="text">
        <label for="autocomplete-input2">Autocomplete 2</label>
      </div>

      <div class="input-field">
        <input id="autocomplete-input3" class="autocomplete" type="text">
        <label for="autocomplete-input3">Autocomplete 3</label>
      </div>

And then initialize them:

    const autocompletes = document.querySelectorAll('.autocomplete');
    M.Autocomplete.init(autocompletes, {
      data: {
        'Apples': null,
        'Oranges': null,
        'Bananas': null
      }, minLength: 0
    });

Then just select options in each autocomplete one by one

As a result, you will see the behavior from the GIF above

bugy added a commit to bugy/materialize that referenced this issue Mar 24, 2021
Smankusors added a commit that referenced this issue Mar 26, 2021
#93 fixed sharing onOptionClick handler in multiple autocomplete instances
bugy added a commit to bugy/materialize that referenced this issue Oct 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants