Comments (5)
There is not currently a way to do this -- but I'm sure it could be added with relative ease to the addTag function. You should fork our code on Github and add it!
Ben Brown
/* I am a software designer and online community pioneer.
Learn more about what I do at http://XOXCO.com & http://PEOPLEPODS.net
and learn more about me at http://BENBROWN.com. */
On Thursday, March 15, 2012 at 10:21 AM, daniel2d2art wrote:
Hi guys!
What best approach for the control, to limit the number of tags allowed to input?
Thx!
Reply to this email directly or view it on GitHub:
#52
from jquery-tags-input.
ok thx Ben!
from jquery-tags-input.
Not the best way i know but i solved it like this:
1. Create a countTags() function
function countTags(tag) {
tagcount = $("span.tag").length;
$("#tags_tag").removeClass("error");
if (tagcount > 4) {
$('#tags').removeTag(tag);
//show a notice to the user and add an error class to the textfield
$(".notification_inline").remove();
$("<span class='tag notification_inline error'>nur 4 Tags erlaubt</span>")
.appendTo('#tags_tagsinput')
.hide()
.fadeIn(300)
.delay(1000)
.fadeOut(300)
.removeTag();
$("#tags_tag").addClass("error");
$("#tags_tagsinput").animate({
"backgroundColor" : 'rgba(250,0,0,0.8)'
}, 300)
.delay(1000).animate({"backgroundColor" : "white"}, 300);
}
}
3. call the countTags() function from the onAddTag() function:
function onAddTag(tag) {
countTags(tag);
}
from jquery-tags-input.
i found a solution can resolve this:
var tagcount = 0; $('#tags').tagsInput({ onAddTag: function(elem, elem_tags){ tagcount += $(this).length; if(tagcount > 6){ alert('You have only 6 tags!'); $(this).removeTag(elem); } }, onRemoveTag: function(){ tagcount -= $(this).length; } });
from jquery-tags-input.
Nice, thanks @notteen!
from jquery-tags-input.
Related Issues (20)
- Prevent tags from being removed?
- get value of removed tag with class in href?
- why does the id of tags change to tags14985314860880 HOT 4
- Cannot set Read Only / Disabled
- Cannot importTags without trigerring callback_function
- How to use a datalist?
- How to destroy tagsInput?
- Autocomplete from an async source?
- Option to edit previous tag by pressing backspace instead of deleting it
- [Bug?] When using multiple delimiters, ALL are used in the output
- [Bug] onChange callback is called twice for every tag removed HOT 1
- Not a codebase issue, but your jsfiddle demo references 404 js and css HOT 1
- Demo link is broken
- tagExist fails when tags are not trimmed
- Issue with 1.3.2-17
- Use UI-autocomplete _renderItem method HOT 3
- width option
- ReferenceError: i is not defined
- 中文输入bug,输入框宽度无法自适应
- jQuery-Tags-Input being blocked by crystal ad blocker on Safari iOS
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jquery-tags-input.