-
Notifications
You must be signed in to change notification settings - Fork 435
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 to validate tags after added #474
Comments
You do not need to remove invalid tags because they are never added to the value of the original input nor they are saves in For tags' validation you can use the var tagify = new Tagify(inputElm, {
// Validate typed tag(s) by Regex. Here maximum chars length is defined as "20"
pattern: /^.{0,20}$/,
}) Another option is to use the var tagify = new Tagify(inputElm, {
transformTag: function(tagData){
// example of basic custom validation
if( tagData.value != 'whatever' )
tagData.value = '' // an empty value will force the tag to be "invalid"
}
}) To learn move about how tagify validates tags, see validateTag method Update (Nov 2020) -The above method ( |
Thank you for quickly answer! Actually something i want like this:
|
You are the one who's making the 500 requests, and you can choose to do 1 request for all those id's, if you listen to the tagify.on('add', onAddTag)
const waitForAllTags = ((allTags, timeout) => {
const validate = () => {
// call ajax once and send "allTags"
console.log(allTags)
// reset "allTags"
allTags.length = 0
}
return data => {
clearTimeout(timeout)
timeout = setTimeout(validate, 200)
allTags.push(data)
}
})([])
function onAddTag(e){
waitForAllTags(e.detail.data)
} |
Yes, i'm doing like that, but i'm getting issue with replaceTag on ajax response. when got response from ajax for 500 ids, example we have 400 valid id and 100 invalid $.ajax(...).done(function (users) {
tagify.value.each(function (tag) {
if (!tag.uid) {// process value which missing id only
if (user = users[v.value]) {// found user, replace tags with username
tagify.replaceTag(tagify.getTagElmByValue(tag.value),
{value: user.display_name + '(' + user.user_login + ')', uid: user.ID}
);
} else {
tagify.removeTag(tag.value);//In valid user, remove/remove with invalid effect tried with replaceTag(...,{__isInvalid:true}) as well but seem not working
}
}
})
}); Both, replaceTag/removeTag not working as expected |
I see the problem. well, it's also not a good idea at all to call SuggestionWhat you could do instead is to remove all the tags entirely ( If you already have 100 "good" tags, which you've done the above for, and now the user adds 100 more, which needs to be transformed also, then you can manually save the state and concatenate to it the newly transformed tags, and again remove all and re-add calling
|
Hi
I'm using this for sending message to users list. Idea is paste a list of ids, then call ajax to validate each id, now i can remove invalid tags with "removeTag" method, but any way to set state for a tag as invalid.
The text was updated successfully, but these errors were encountered: