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

Awesomplete with one field crashes #16790

Open
IonicaBizau opened this issue Nov 29, 2015 · 3 comments
Open

Awesomplete with one field crashes #16790

IonicaBizau opened this issue Nov 29, 2015 · 3 comments

Comments

@IonicaBizau
Copy link

I discovered this little thing: if the input has data-list="Ada", Awesomplete will not work:

image

@LeaVerou Nice project! ✨

@vlazar
Copy link
Collaborator

vlazar commented Nov 29, 2015

In this case it treats the value of data-list attribute to as CSS selector, not a comma-separated list of values. See https://github.com/LeaVerou/awesomplete/blob/gh-pages/awesomplete.js#L120-L123

@IonicaBizau I'm curious, what is your use case, where you get this error?

@IonicaBizau
Copy link
Author

@vlazar I have an array of strings and I join(",") them in the data-list attribute. Since the array is kind of dynamic, I cannot (in my case I can!!! 😄) control it.

But anyway, I guess the error should be friendlier. 📝

@vlazar
Copy link
Collaborator

vlazar commented Nov 30, 2015

@IonicaBizau Since you already have an array of strings, you can use another way as described in docs:

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

However, someone may prefer to put inline list in data-list attribute and not having to handle any special case, like one item in a list.

I feel this is related to #16725 (comment) . Maybe awesomplete.list setter API is overloaded. One possible solution would be to split CSS selector related portion of setter from other code. So it would be something like this:

// init from some element with CSS selector
completer.list = "#some-id";
completer.list; // "#some-id"
completer.items; // [ "array", "of", "items", "from", "some-id" ];

// init from items (Array or comma-separated list)
completer.items = [ "list", "of", "items" ];
completer.items; // [ "list", "of", "items" ]

completer.items = "comma,separated,list";
completer.items; // [ "comma", "separated", "list" ]

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

No branches or pull requests

2 participants