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

How do you get the values out? #6

Closed
stargazing-dino opened this issue Jun 3, 2020 · 2 comments
Closed

How do you get the values out? #6

stargazing-dino opened this issue Jun 3, 2020 · 2 comments

Comments

@stargazing-dino
Copy link

For example, I want to listen to the enter event and get the the strings out:

let tagger = tagger(document.querySelector('[name="tags"]'), {allow_spaces: false});

tagger.complete((results) {
  console.log(results); // []string
});

But that doesn't really work

@jcubic
Copy link
Owner

jcubic commented Jun 3, 2020

First you have syntax error if you use arrow function you =>.
Second the comple is not to get the value out of the input but to complete the word. like any autocomplete function, you type foo and press tab:

tagger.complete("fo");

actual value is on the input, you need to use:

var input = document.querySelector('[name="tags"]');
console.log(input.value);

to get the tags. if you want array use input.value.split(','); I should probably document that.

I've updated the demo https://codepen.io/jcubic/pen/YbYpqO

I should probably add change event, so you can listen to tags adding and removing. Also complete API method don't exactly work, the library use datalist that have limitations, even if you focus on input and then called that function the list don't show up.

@stargazing-dino
Copy link
Author

Got it, Thanks!

Splitting the value on the element works just fine for me

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