I'm trying to convert this Tagify script from an array to a string. The problem is all the output from Tagify contains value and comma's and I've so far been unable to convert these array's to a nice string. How would I go about this?
I'm using the script to create tags that are then used in a search (GET). I get this in the URL ?query=[{"value"%3A"bee"}]
instead of ?query=bee
var input = document.querySelector('input[name=query]'),
// init Tagify script on the above inputs
tagify = new Tagify(input, {
// after 2 characters typed, all matching values from this list will be suggested in a dropdown
whitelist: ["Door", "Cat", "Mouse", "Chicken", "Duck"]
})
To change the format, assuming your tags have no commas you can use the originalInputValueFormat
setting:
var tagify = new Tagify(input, {
// after 2 characters typed, all matching values from this list will be suggested in a dropdown
whitelist: ["Door", "Cat", "Mouse", "Chicken", "Duck"],
originalInputValueFormat: valuesArr => valuesArr.map(item => item.value).join(', ')
})
Output: "Cat, Mouse"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With