Coder Social home page Coder Social logo

Tags input limit about jquery-tags-input HOT 5 CLOSED

xoxco avatar xoxco commented on June 2, 2024
Tags input limit

from jquery-tags-input.

Comments (5)

benbrown avatar benbrown commented on June 2, 2024

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.

daniel2d2art avatar daniel2d2art commented on June 2, 2024

ok thx Ben!

from jquery-tags-input.

oliverkierepka avatar oliverkierepka commented on June 2, 2024

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.

phuongdev89 avatar phuongdev89 commented on June 2, 2024

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.

jokewd avatar jokewd commented on June 2, 2024

Nice, thanks @notteen!

from jquery-tags-input.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.