Skip to content

Instantly share code, notes, and snippets.

@douglasmiranda
Created January 7, 2021 16:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save douglasmiranda/1c7ddb36eee035687f5f371c77b3ea28 to your computer and use it in GitHub Desktop.
Save douglasmiranda/1c7ddb36eee035687f5f371c77b3ea28 to your computer and use it in GitHub Desktop.
Tagify: Format for server side comma separated / on form changes event / jQuery example
jQuery(document).ready(function ($) {
$input = $('#my-form')
.tagify()
.on('change', function (e, tagData) {
if (tagData === undefined) {
return;
}
// string [{"value":"test"}', '{"value":"test2"}] to JSON Object
var tags = JSON.parse(tagData);
// Converts into a simple array ["test", "test2"], then convert to string "test,test2"
var tags_parsed = tags.map(item => item.value).toString();
// Then you can do some ajax post and send the tags_parsed to the server side.
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment