Skip to content

Commit 1b46162

Browse files
author
Javier Toledo
committed
Mark as not_valid the fake input on repeated tag
I have added some code to add a not_valid class to the fake input to be able to stylish it when some value is repeated and I have selected the unique option.
1 parent ffac87c commit 1b46162

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

jquery.tagsinput.css

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jquery.tagsinput.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@
3333

3434
if (options.unique) {
3535
var skipTag = $(tagslist).tagExist(value);
36+
if(skipTag == true) {
37+
//Marks fake input as not_valid to let styling it
38+
$('#'+id+'_tag').addClass('not_valid');
39+
}
3640
} else {
3741
var skipTag = false;
3842
}
@@ -245,6 +249,14 @@
245249
});
246250
$(data.fake_input).blur();
247251

252+
//Removes the not_valid class when user changes the value of the fake input
253+
if(data.unique) {
254+
$(data.fake_input).keydown(function(event){
255+
if(event.keyCode == 8 || String.fromCharCode(event.which).match(/\w+|[áéíóúÁÉÍÓÚñÑ,/]+/)) {
256+
$(this).removeClass('not_valid');
257+
}
258+
});
259+
}
248260
} // if settings.interactive
249261
return false;
250262
});

0 commit comments

Comments
 (0)