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

Support for user to select multiple results #91

Closed
arnav13081994 opened this issue Nov 28, 2019 · 7 comments
Closed

Support for user to select multiple results #91

arnav13081994 opened this issue Nov 28, 2019 · 7 comments
Labels
enhancement New feature or request

Comments

@arnav13081994
Copy link

Is your feature request related to a problem? Please describe.

It would be great if a user can search for and add multiple inputs from the same search results. Perhaps just exposing an attribute in the autocomplete configure like multiple: true, would be very nice. Most Autocomplete use-cases would involve multiple inputs

Thoroughly Describe the solution you'd like
By simply setting an attribute like multiple: true in autocomplete configure should allow a user to input multiple and eventually select multiple results.

Please provide a few use cases for this feature

  1. A user wants to search for foods they would like to eat. For most people, it would be more than 1 type of food like burger, pizza etc.

Please Describe alternatives you've considered
A hacky solution is to store the resulted solution somewhere else on the page and keep on repeating until the user is done searching.

@arnav13081994 arnav13081994 added the enhancement New feature or request label Nov 28, 2019
@samijnih
Copy link

I'm facing the same issue!

Could be cool to support this feature

@TarekRaafat
Copy link
Owner

Hello @samijnih,

I totally get the use-cases of multiple selections. Yet, I don't see it as a built-in functionality inside autoComplete.js it's better to be developed separately as a plugin instead for several reasons from my point of view, and please correct me if you don't agree.

  1. Not every use of autocomplete functionality involves multiple selections
  2. It will overload the library while it's not a core function of autocompleting
  3. It could be implemented in many different ways depends on the project and the developer "gets subjective"

I hope I'm making any sense, please let me know your thoughts.

Have a nice day, cheers! :)

@samijnih
Copy link

samijnih commented Dec 16, 2020

Hey @TarekRaafat

Thanks for taking time to answer. I got your three points and that's true. It's not a core autocomplete feature.

Anyway, I've managed to do it with your hackable autocomplete by using callback on user selection 👍

I'll post my solution in order to provide to @arnav13081994 a sample of how to deal with it 😋

Have a nice day too! :)

@TarekRaafat
Copy link
Owner

@samijnih that's awesome!

Thanks for your understanding, and I'm looking forward to your solution.

Cheers! :)

@samijnih
Copy link

@TarekRaafat @arnav13081994

here we are!

https://codepen.io/everytimeicob/pen/NWRjajL

I'm using materializecss for chip elements. I don't use their API because it puts the chip element over the input and so, it's not the expected behaviour.

Have a nice night :)

@TarekRaafat
Copy link
Owner

TarekRaafat commented May 3, 2021

Here is another basic example for multiple selections.

@masiorama
Copy link

masiorama commented Feb 8, 2022

Here is another basic example for multiple selections.

Hello @TarekRaafat, I believe your example doesn't work with version 10. I tried to change version on your code pen (10.2.6) and the widget simply doesn't work anymore.

edit: I somehow managed to make it work replacing resultList configuration with something like this:

resultsList: {
    element: (list, data) => {
        if (!data.results.length) {
            // Create "No Results" message element
            const message = document.createElement("div");
            // Add class to the created element
            message.setAttribute("class", "no_result");
            // Add message text content
            message.innerHTML = `<span>Found No Results for "${data.query}"</span>`;
            // Append message element to the results list
            list.prepend(message);
        }
    },
    noResults: true,
},

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants