LeaVerou / awesomplete

Ultra lightweight, usable, beautiful autocomplete with zero dependencies.
http://leaverou.github.io/awesomplete/
MIT License
6.97k stars 611 forks source link

Input: strings, output: object #17081

Open El4a opened 7 years ago

El4a commented 7 years ago

Hello,

I've noticed that when you init the typeahead with a list of strings (be it as a data-list or as an option through the js-way), you get an object returned when the awesomplete-selectcomplete event is fired (with both "label" and "value" properties set to the same content). Wouldn't it make more sense to just return the selected literal, instead of wrapping in an object?

So the example of var input = document.getElementById("myinput"); new Awesomplete(input, { list: ["Ada", "Java", "JavaScript", "Brainfuck", "LOLCODE", "Node.js", "Ruby on Rails"] });

when logging the event.text on selecting one of these gives you : text { label: "Ada", value: "Ada" }

instead of just "Ada".

I was trying to look for a solution in the lib, and as far as I understand it's because a constructor ( as used for Suggestion() ) can only return an object and not a literal? It just seems a bit odd to return a selected value in a different format than it was entered.

annafractuous commented 7 years ago

Hi El4a,

I'm not too familiar with this library (haven't started using it yet, just looking into it), but my guess is that this is because Awesomplete supports entering different text for the label and the value, and returning event.text as an object maintains consistency of format whether the label & value match or not.

screen shot 2017-07-12 at 11 08 48 am