Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert Tagify javascript array to string

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"]
  })
like image 340
E Wilson Avatar asked Oct 18 '25 00:10

E Wilson


1 Answers

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"

like image 164
Micah Avatar answered Oct 20 '25 14:10

Micah