Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6606097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:21:35+00:00 2026-05-25T19:21:35+00:00

Hi i have this little plugin installed: (function($) { $.fn.tagfield = function(options) { if

  • 0

Hi i have this little plugin installed:

    (function($) {
  $.fn.tagfield = function(options) {
    if (options && options.add) {
      this.each(function(i, elem) {
        add_tags(elem, options.add);
      });
    } if (options && options.remove) {
      this.each(function(i, elem) {
        remove_tags(elem, options.add);
      });
    } else {
      this.each(function(i, elem) {
        var initial_tags = $(elem).val();
        $(elem).val('');

        tagfield(this, $(elem));

        $(initial_tags.split(',')).each(function(i, v) {
          v = $.trim(v);
          if (v !== '') add_tags(elem, v);
        })
      });
    }
  };

  var KEYS = {
    "enter": "\r".charCodeAt(0),
    "space": " ".charCodeAt(0),
    "comma": 188,
    "backspace": 8
  };

  var tagfield_id_for = function(real_input) {
    return $(real_input).attr('id') + '_tagfield';
  };

  var add_tags = function(real_input, text) {
    remove_tags(real_input, text);
    var tag = $('<span class="tag">').append('<span class="text">' + text +'</span>'),
        close = $('<a class="close" href="#">X</a>');
    close.click(function(e) {
      remove_tags(real_input, text);
    });
    tag.append(close);
    $('#' + tagfield_id_for(real_input) + " .tags").append(tag);

    real_input = $(real_input);
    real_input.val(($.trim(real_input.val()) === '' ? [] : real_input.val().split(',')).concat([text]).join(','));
  };

  var remove_tags = function(real_input, text) {
    $('#' + tagfield_id_for(real_input) + " .tags .tag").each(function(i, v) {
      v = $(v);
      if (v.find('.text').html() === text) {
        v.remove();
        real_input = $(real_input);

        var tags = $(real_input.val().split(',')).filter(function(i, v) {
          return v !== text;
        });
        real_input.val(Array.prototype.join.call(tags));
      }
    });
  };

  var tagfield = function(real_input, elem) {
    var tagfield = $('<div class="tagfield">').attr('id', tagfield_id_for(real_input)),
        input = $('<input type="text"/>'),
        buffer = $('<span class="buffer">'),
        tags   = $('<span class="tags">');
    tagfield.append(tags);
    tagfield.append(buffer);
    tagfield.append(input);

    tagfield.click(function(e) {
      input.focus();
    });

    var check_add_tag = function() {
      if (buffer.html()) {
        var tag_text = buffer.html();
        buffer.html('');
        add_tags(real_input, tag_text);
      }
    };

    var add_tag = function(text) {
    };

    input.keydown(function(e) {
      if (e.which === KEYS.enter || e.which === KEYS.space || e.which === KEYS.comma) {
        e.preventDefault();
        check_add_tag();
      }

      if (e.which === KEYS.backspace) {
        if (buffer.html() === "") {
          remove_tags(real_input, tagfield.find('.tag').last().find('.text').html());
        } else {
          var s = buffer.html();
          buffer.html(s.slice(0, s.length-1));
        }
      }
    });

    input.blur(check_add_tag);

    input.keyup(function(e) {
      buffer.append(input.val());
      input.val('');
    });

    $(real_input).hide().after(tagfield);
  };

})(jQuery);

does anyone can show me how can i call the methods add_tags() and remove_tags() ?

thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T19:21:36+00:00Added an answer on May 25, 2026 at 7:21 pm
    $("selector").tagfield({remove:someobject}); 
    $("selector").tagfield({add:someobject});
    

    but the “remove” thing will not work i think, since the second “if” in fn.tagfield watches for “options.remove” but removes the “options.add” …

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this little function function makewindows(){ child1 = window.open (about:blank); child1.document.write(<?php echo htmlspecialchars(json_encode($row2['ARTICLE_DESC']),
I have this little script to toggle a contact form when a button is
I have this little rake task: namespace :db do namespace :test do task :reset
I have this little problem, that I cannot figure out which arguments to pass
I have this nice little MSBuild-based daily build setup that I use on my
I've searched for this a little but I have not gotten a particularly straight
Googling this does little good, as you can imagine. Does anyone have resources that
This is a little out there but I have a customer object coming back
This is a little different than the questions that have already been asked on
On this page there is a list of footer links that have a little

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.