Hi,
I updated to the newer version, but now when I get the tags input value (.val() method) I'm getting :
[{value:fr}]
Anyway to just get the 'fr' ?
Thanks in advance,
Julien
You need to parse it yourself either on the client or the server.
Why is this a problem?
Using simple string value is not a good idea at all, for example, here's how a simple one will look:
"css,html,javascript"
But, for this will not work for values which has commas in them, for example, a tags input for addresses:
tag 1: city1, state1
tag 2: city2, state2
both tags have commas in them, and making a string out of the values will look like this:
city1, state1, city2, state2
Which is far from ideal.
There are also other considerations besides the above scenario that had let me choose the current format, for example, tags can have variable attributes. A user can toggle tags on/off and that state needs to be saved, so raw data representation is ideal.
I see, good point. Thanks for your answer.
Maybe you have an easy way to parse it then ?
var value = JSON.parse( tagifyInput.val() )
Situation- Using Tagify inside my django project within bootstrap 4 model. When I was sending data via $(this).serialize, it was not appropriate. So this is how I made an appropriate data format. (Also, I need not to install django-tagify). Hope below method will help some one.
var TagValues = JSON.parse($('[name=tags]').tagify().val())
var TagArray = []
for(let i=0;i<TagValues.length;i++){
TagArray.push(TagValues[i].value)
}
var dataToSend = $(this).serializeArray();
for (let index = 0; index < dataToSend.length; ++index) {
if (dataToSend[index].name == "tags") {
dataToSend[index].value = TagArray;
break;
}
}
And then I update params that needs to be update using jQuery.param(dataToSend)
ajax({
url: url,
method: httpMethod,
data: jQuery.param(dataToSend)
})
Thanks for the beautiful Plugin.
To retrieve the data from tagify on your django view just use the eval() built-in function.
lets say in your form you have:
<input type='text' name='tags'>
So, in your view you would do:
tags = eval(request.POST['tags']),
then you can loop as such:
for tag in tags:
print(tag['value'])
To retrieve the data from tagify on your django view just use the
eval()built-in function.lets say in your form you have:
<input type='text' name='tags'>So, in your view you would do:
tags = eval(request.POST['tags']),then you can loop as such:
for tag in tags:
print(tag['value'])
I also just wanted to chime in say if your going with the above solution, you might want to consider using Python's built-in json module instead of eval. Building off from the above example.
import json
...
tags = json.loads(request.POST['tags'])
...