Git Product home page Git Product logo

tag-it's Introduction

Tag-it: a jQuery UI plugin


IMPORTANT: tag-it is unmaintained.

Tag-it has reached end-of-life, and we're not looking to update or maintain it. This library should still work, but there are many PRs open and forks that you might want to consider before using it.

As a tag-it replacement, we currently recommend tagify, which appears to be a popular library that is still being actively developed as of late 2023.

Thank you!


Tag-it is a simple and configurable tag editing widget with autocomplete support.

Homepage

Demo

Screenshot

Check the examples.html for several demos and the prototype.js file for a JavaScript prototype with all options and events.

Usage

First, load jQuery (v1.4 or greater), jQuery UI (v1.8 or greater), and the plugin:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js" type="text/javascript" charset="utf-8"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.12/jquery-ui.min.js" type="text/javascript" charset="utf-8"></script>
<script src="js/tag-it.js" type="text/javascript" charset="utf-8"></script>

If you're using a custom jQuery UI build, it must contain the Core, Widget, Position, and Autocomplete components. The Effects Core with "Blind" and "Highlight" Effect components are optional, but used if available.

The plugin requires either a jQuery UI theme or a Tag-it theme to be present, as well as its own included base CSS file (jquery.tagit.css). Here we use the Flick theme as an example:

<link rel="stylesheet" type="text/css" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1/themes/flick/jquery-ui.css">
<link href="css/jquery.tagit.css" rel="stylesheet" type="text/css">

Now, let's attach it to an existing <ul> box:

<script type="text/javascript">
    $(document).ready(function() {
        $("#myTags").tagit();
    });
</script>

<ul id="myTags">
    <!-- Existing list items will be pre-added to the tags -->
    <li>Tag1</li>
    <li>Tag2</li>
</ul>

This will turn the list into a tag-it widget. There are several other possible configurations and ways to instantiate the widget, including one that uses a single comma-delimited input field rather than one per tag, so see the Options documentation below as well as the examples page (and its source) which demonstrates most of them, as well as the Tag-it Zendesk theme used in the screenshot above.

Theming

Tag-it is as easily themeable as any jQuery UI widget, using your own theme made with Themeroller, or one of the jQuery UI premade themes. The old ZenDesk-like theme is included as an optional CSS file (tagit.ui-zendesk.css).

Options

Tag-it accepts several options to customize its behaviour:

fieldName (String)

Each tag's hidden input field will have this name. If you're using PHP, you may want to use something like itemName[fieldName][] for this option's value.

$("#myTags").tagit({
    fieldName: "skills"
});

Defaults to tags.

availableTags (Array)

Used as source for the autocompletion, unless autocomplete.source is overridden.

$("#myTags").tagit({
    availableTags: ["c++", "java", "php", "javascript", "ruby", "python", "c"]
});

If you define your own autocomplete.source, this option is unused (unless you choose to reference it yourself from your custom autocomplete.source of course.)

Defaults to an empty array [].

autocomplete (Object)

Allows overriding the source and select options that are set by default, as well as adding any other options you want to pass to the jQuery UI Autocomplete widget, such as minLength or delay.

The autocomplete.source should be overridden if you want to use custom autocompletion sources, like an Ajax / XHR response.

For example:

$("#myTags").tagit({
    autocomplete: {delay: 0, minLength: 2}
});

The default autocomplete.source function filters the strings in availableTags and subtracts the already assigned tags. It also positions autocomplete underneath tag input. See the full list of available options here.

showAutocompleteOnFocus (boolean)

Shows autocomplete when the tag input first receives focus, before the user even types anything.

If enabled, this will also make autocomplete.minLength default to 0 unless you override that, so that autocomplete can show up with a blank search.

Defaults to false.

removeConfirmation (boolean)

When removeConfirmation is enabled the user has to press the backspace key twice to remove the last tag. After the first keypress the last tag receives a remove css class which can be used to visually highlight the tag.

Defaults to false.

caseSensitive (boolean)

whether the duplication check should do a case sensitive check or not.

Defaults to true.

allowDuplicates (boolean)

Allows duplicate tags to be created. One implication of this is that removeTagByLabel will remove all tags which match the given label.

Defaults to false.

allowSpaces (boolean)

When allowSpaces is enabled the user is not required to wrap multi-word tags in quotation marks. For example, the user can enter John Smith instead of "John Smith".

Defaults to false.

readOnly (boolean)

When enabled, tag-it just render tags. It disables the ability to edit tags.

Defaults to false.

tagLimit (integer)

Limits the total number of tags that can be entered at once. Note that if you use this option with preloaded data, it may truncate the number of preloaded tags. Set to null for unlimited tags. See the onTagLimitExceeded callback for customizing this behavior.

Defaults to null.

singleField (boolean)

When enabled, will use a single hidden field for the form, rather than one per tag. It will delimit tags in the field with singleFieldDelimiter.

Defaults to false, unless Tag-it was created on an input element, in which case singleField will be overridden as true.

singleFieldDelimiter (String)

Defaults to ","

singleFieldNode (DomNode)

Set this to an input DOM node to use an existing form field. Any text in it will be erased on init. But it will be populated with the text of tags as they are created, delimited by singleFieldDelimiter. If this is not set, we create an input node for it, with the name given in fieldName.

Defaults to null, unless Tag-it was created on an input element, in which case singleFieldNode will be overridden with that element.

tabIndex (integer)

Optionally set a tabindex attribute on the input that gets created for tag-it user input.

Defaults to null

placeholderText (String)

Optionally set a placeholder attribute on the input that gets created for tag-it user input.

Defaults to null

Events

beforeTagAdded (function, Callback)

Can be used to add custom behaviour before the tag is added to the DOM.

The function receives a null event, and an object containing the properties tag, tagLabel, and duringInitialization.

duringInitialization is a boolean indicating whether the tag was added during the initial construction of this widget, e.g. when initializing tag-it on an input with preloaded data. You can use this to tell whether the event was initiated by the user or by the widget's initialization.

To cancel a tag from being added, simply return false in your event callback to bail out from adding the tag and stop propagation of the event.

$("#myTags").tagit({
    beforeTagAdded: function(event, ui) {
        // do something special
        console.log(ui.tag);
    }
});

afterTagAdded (function, Callback)

Behaves the same as beforeTagAdded except that it fires after the tag has been added to the DOM. It too receives the duringInitialization parameter — see beforeTagAdded for details.

beforeTagRemoved (function, Callback)

Can be used to add custom behaviour before the tag is removed from the DOM.

To cancel a tag from being removed, simply return false in your event callback to bail out from removing the tag and stop propagation of the event.

The function receives a null event, and an object with tag and tagLabel properties.

$("#myTags").tagit({
    beforeTagRemoved: function(event, ui) {
        // do something special
        console.log(ui.tag);
    }
});

afterTagRemoved (function, Callback)

Behaves the same as beforeTagRemoved except that it fires after the tag has been removed from the DOM.

onTagExists (function, Callback)

Triggered when attempting to add a tag that has already been added in the widget. The callback receives a null event, and an object containing the properties existingTag and duringInitialization, since technically you could try to preload duplicate tags during the widget initialization.

If the allowDuplicates option is enabled, this will not be triggered.

By default it will visually highlight the existing tag, unless you return false in your callback.

onTagClicked (function, Callback)

Can be used to add custom behaviour when the tag is clicked. The function receives the click event and an objecting containing tag and tagLabel properties.

$("#myTags").tagit({
    onTagClicked: function(event, ui) {
        // do something special
        console.log(ui.tag);
    }
});

onTagLimitExceeded (function, Callback)

Called when attempting to create a tag while the tag limit has already been reached. Receives a null event, and an object with the property duringInitialization. This can only be called if tagLimit is set.

Methods

assignedTags()

Returns an array of the text values of all the tags currently in the widget.

$("#myTags").tagit("assignedTags");

createTag(tagLabel, additionalClass)

Adds new tag to the list. The additionalClass parameter is an optional way to add classes to the tag element.

$("#myTags").tagit("createTag", "brand-new-tag");

preprocessTag(function, Callback)

Set a function to be called before tag is created. Callback receives the value of the tag created.

// ensure all tags are capitalized
$(#tag-it").tagit("preprocessTag", function(val) {
  if (!val) { return ''; }
  return val[0].toUpperCase() + val.slice(1, val.length);
});
// foo -> Foo

removeTagByLabel(tagLabel, animate)

Finds the tag with the label tagLabel and removes it. If no such tag is found, it'll throw an exception.

$("#myTags").tagit("removeTagByLabel", "my-tag");

removeAll()

Clears the widget of all tags — removes each tag it contains, so the beforeTagRemoved / afterTagRemoved event callbacks (if set) will be called for each.

$("#myTags").tagit("removeAll");

Properties

tagInput

The <input> field which is used for entering new tags. It's a jQuery object, so you may use it to add a class or anything to it, e.g.:

$("#myTags").data("ui-tagit").tagInput.addClass("fancy");

Authors

License

tag-it is released under the MIT license.

tag-it's People

Contributors

aehlke avatar afzalmasood11 avatar andrusha avatar benoberkfell avatar berwinter avatar cail avatar chung-leong avatar coil avatar gosukiwi avatar gregarcara avatar grobie avatar gui avatar ibiryukov avatar jobywalker avatar jpotterm avatar julen avatar jzohrab avatar kevinslin avatar levycarneiro avatar matthandlersux avatar nabuchodonozor avatar nolanlawson avatar ptr07 avatar sameer711 avatar shiftb avatar sonots avatar sskylar avatar timrchavez avatar toao avatar yavari avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

tag-it's Issues

Add after tag added/removed events

Hi

I just added these events to my local tagit as in the patch below.

Might be useful to someone else, consider merging?

ciao

Campey

diff -r e1abd7d74ee7 mm-gae/web/rich/scripts/tagit/tag-it.js
--- a/mm-gae/web/rich/scripts/tagit/tag-it.js   Wed Jan 18 17:06:20 2012 +0200
+++ b/mm-gae/web/rich/scripts/tagit/tag-it.js   Wed Jan 18 17:23:36 2012 +0200
@@ -74,7 +74,9 @@

             // Event callbacks.
             onTagAdded  : null,
+            afterTagAdded  : null,
             onTagRemoved: null,
+            afterTagRemoved: null,
             onTagClicked: null
         },

@@ -346,6 +348,8 @@

             // insert tag
             this._tagInput.parent().before(tag);
+
+            this._trigger('afterTagAdded', null, tag);
         },

         removeTag: function(tag, animate) {
@@ -371,6 +375,8 @@
             } else {
                 tag.remove();
             }
+
+            this._trigger('afterTagRemoved', null, tag);
         },

         removeAll: function() {

unknown method 'propAttr' during autocomplete

My instantiation looks like:

$('#website_tag_picker').tagit({
  allowSpaces: true,
  removeConfirmation: true,
  tagSource: function(search, showChoices) {
                  var filter = search.term.toLowerCase();
                  $.getJSON('/ajax/getTags?term='+filter,
                    function(data){
                      var tags = data.map(function(tag){ return tag['value']; }),
                          choices = subtractArray(tags, $('#website_tag_picker').tagit('assignedTags'));
                      console.log(choices);
                      showChoices(choices);
                    }
                  );
              }
})

Without the tagSource option, the widget loads correctly, and works fine in all ways. With it, I get the error (in Chrome):

Uncaught TypeError: Object [object Object] has no method 'propAttr'
a.widget._create.element.addClass.attr.attr.bind.bind.hjquery-ui.min.js:239
f.event.handlejquery.min.js:17 
f.event.add.i.handle.k

Nothing ever gets console.log'd. I'm totally at a loss. Am i doing something dumb? (subtractArray is defined in scope)

More flexible field names

Please add an option to specify the complete field name; not just parts of it.

name="' + this.options.itemName + '[' + this.options.fieldName + '][]" is fine for PHP people but not everyone uses PHP. In most Python frameworks for example you do not specify arrays using [] but by simply using a different function on the server side which returns a list instead of a single element. And request.form.getlist('foo[bar][]') is pretty ugly.

Handling two words tags (available tags)

Hi, it would be nice to have option to set to split the tag into words (OR search)
For example if you have available tags:

"cool pictures", "nice pictures"

Those tags will only appear in the autosuggest if you type "cool", or "nice" but nothing happens if you type "pictures"

Problems with singleFieldDelimiter

I use singleFieldDelimiter: ";" because i need to be able to insert tags with ",".

Problem 1
tagit config:
{
allowSpaces: true,
singleFieldDelimiter: ";"
}

Go to the input field and type "Auto, Fahrrad"
Now it ads two tags "Auto" "Fahrrad" :-/

Problem 2
tagit config:
{
allowSpaces: true,
singleFieldDelimiter: ";"
}

Go to the input field and type "Türe; Fenster" and press "enter"
Not it ads one tag "Türe; Fenster"

Update tags when hidden field changes

How to update tags, when tag-it input value has changed?

I want to do smth like that:

    <input name="tags" id="tags" value="hello, world" />
    $('#tags').tagit();

    $('#tags').val('hello,world,foobar');
    $('#tags').tagit('update'); // update tags based on input value

Maybe there is a fork with this feature?

Comma detection broken on foreign keyboards

Hi,

The way tag-it detects a comma keypress does not work on some keyboard layouts. For example, in the Hebrew keyboard layout the comma is on a different key, and where the comma usually is - there's the letter Tav. So when you use tag-it with such a keyboard, each time you try to input a word with Tav in it, the tag is closed instead.

I've implemented a very simple fix, which uses event.charCode to detect the comma instead of relying on $.ui.keyCode.COMMA
Handling the comma then has to be moved to the keypress event instead of keydown, because event.charCode is not available on keydown. See below:

            // Events.
            this._tagInput
                .keydown(function(event) {
                    // Backspace is not detected within a keypress, so it must use keydown.
                    if (event.which == $.ui.keyCode.BACKSPACE && that._tagInput.val() === '') {
                        var tag = that._lastTag();
                        if (!that.options.removeConfirmation || tag.hasClass('remove')) {
                            // When backspace is pressed, the last tag is deleted.
                            that.removeTag(tag);
                        } else if (that.options.removeConfirmation) {
                            tag.addClass('remove ui-state-highlight');
                        }
                    } else if (that.options.removeConfirmation) {
                        that._lastTag().removeClass('remove ui-state-highlight');
                    }

                    // Space/Enter are valid delimiters for new tags,
                    // except when there is an open quote or if setting allowSpaces = true.
                    // Tab will also create a tag, unless the tag input is empty, in which case it isn't caught.
                    if (
                        event.which == $.ui.keyCode.ENTER ||
                        (
                            event.which == $.ui.keyCode.TAB &&
                            that._tagInput.val() !== ''
                        ) ||
                        (
                            event.which == $.ui.keyCode.SPACE &&
                            that.options.allowSpaces !== true &&
                            (
                                $.trim(that._tagInput.val()).replace( /^s*/, '' ).charAt(0) != '"' ||
                                (
                                    $.trim(that._tagInput.val()).charAt(0) == '"' &&
                                    $.trim(that._tagInput.val()).charAt($.trim(that._tagInput.val()).length - 1) == '"' &&
                                    $.trim(that._tagInput.val()).length - 1 !== 0
                                )
                            )
                        )
                    ) {
                        event.preventDefault();
                        that.createTag(that._cleanedInput());

                        // The autocomplete doesn't close automatically when TAB is pressed.
                        // So let's ensure that it closes.
                        that._tagInput.autocomplete('close');
                    }
                }).keypress(function(event){
                    // Comma character (has to be checked on keypress, because charCode is 0 in keydown event)
                    if (event.charCode == 44) {
                        event.preventDefault();
                        that.createTag(that._cleanedInput());
                    }
                }).blur(function(e){
                    // Create a tag when the element loses focus (unless it's empty).
                    that.createTag(that._cleanedInput());
                });

tag is undefined

Around line 252:

  if( (tag !== undefined) && this.options.tagsChanged ) {
    this.options.tagsChanged(tag.value || tag.label, 'popped', null);
  }

This is to fix the error that appears when you hit backspace on an empty tag set more than once. (Just keep hitting backspace and eventually the tag variable will become undefined.)

Example page issue with first-time use of close buttons

On the example page - http://aehlke.github.com/tag-it/examples.html - I'm seeing a problem in Chrome/OSX where clicking the close button of a tag doesn't do things like create the alerts for events or remove the tag from the hidden input.

Clearest example is "Single input field". Click on the close button to remove "orange" and it is not removed from the hidden input. Bizarrely, if you then remove "orange" from "Single input field (2)" it gets removed from the input.

Errors when removing tags (jQuery 1.6.1)

Using jQuery 1.6.1.

When removing a tag (clicking on its remove link or pressing backspace) I get the following error on JS console:

Errors

After that error seems that:

  • I can't remove any tags with backspace, only by using the remove link.
  • If I add a new tag then I can remove last tag with backspace, but only that one. Remove links keep working though.
  • Doesn't result on a real tag removal, as I can't add a new tag with the name of a removed tag. It seems that tag-it thinks that this is a duplicate tag.

I'm using a simple JS call:

$("input.share_with").tagit({
     'caseSensitive': false
 });

With no options I have the same issue, so doesn't seem to be the 'caseSentisitve' option.

I can reproduce this issue on Chrome (12.0.718.0) and Firefox (3.6.17)

KnockoutJs bindings not being updated

I was having an issue with knockout bindings not being updated using this plugin. Seems to work when calling the 'change' method for the _updateSingleTagsField function:

$(this.options.singleFieldNode).val(tags.join(this.options.singleFieldDelimiter)).change();

Might be useful for someone else using knockout, unless there is a better way to do this...

Issue while loading taggit function after an ajax request

Hi,
I am using the plugin to load the tags to a text box. The tags will be retrieved from an Ajax request which will be called onload. The plugin will work properly if i attach the tagit function to the element before the ajax request. But if i try to set the available tags from the ajax request response there will be an error "$("#tag").tagit is not a function" .

the code is like this

$(function()
{
setTags();
});

function setTags()
{
$(":input").each(function(index) {
var elementId = '#'+(this.id);
var tagAttribute = $(elementId).attr('tag');
if(typeof tagAttribute !== 'undefined' && tagAttribute !== false)
{
var data = {};
var url = absoluteurl+'/tags.php';
data['tg'] = tagAttribute;

        //response = ['PHP','MYSQL','JAVA','JAVASCRIPT'];
        $.post(url,data,function(response)
        {
        setTagResponses(response, elementId);
         },'json');

    }
});

}

function setTagResponses(tags, elementId)
{
if(tags.length > 0)
{
$(elementId).tagit({
availableTags: tags
});
}
}

How to get tagSource to work with $.ajax()?

Everything works so far. Except, I am unable to assign a tagSource via an ajax call.

In firebug, the 'data' is returning:

["Ruby","Ruby On Rails"]

But its not showing up as I type into the input box.

$('.tags ul').tagit({
  itemName: 'question',
  fieldName: 'tags',
  removeConfirmation: true,
  availableTags: ["c++", "java", "php", "javascript", "ruby", "python", "c"],
  allowSpaces: true,
  // tagSource: ['foo', 'bar']
  tagSource: function() {
    $.ajax({
      url:        "/autocomplete_tags.json",
      dataType:   "json",
      data:       { term: 'ruby' },
      success:    function(data) {
        eturn data;
      }
    });
  }
});

Am I missing something here?

undefined url

It seems no matter how I use tag-it, with or without autocomplete and/or availableTags, every key-press tries to send the query to "/undefined". Even if I try to override the autocomplete source parameter or even hardcode a url in there I get the same results. Any idea on what it can be?

Add an ID to the generated input field

Hi

I need to add an id to the generated input field. I'm doing tagit on an input field. It would be nice if I could do something like

$('#tag_input').tagit({'id': 'tagit_input'});

I need this because my backbone app depends on actions to the input field.

Deleting a tag throws an error

If you type a few tags in, then hit "backspace/delete" with your keyboard, deleting a tag throws an error in the console:

Uncaught TypeError: Property '#' of object # is not a function

The error is problematic in that it doesn't actually delete the tag from the internal list, so the user cannot type the tag back in if they decide they want it again. IE, I type tag "todo", delete it, then am not able to submit "todo" again. I could submit "todos" as it is a different word.

RTL languages

there is two bugs on RTL languages:

  1. When switching to other language then English, the keydown check "event.which == $.ui.keyCode.COMMA" is wrong. To fix it, change it to "event.charCode == 44" on a keypress event.
  2. CSS only work for LTR direction.

Block non-existent tags

Hi,

how is possible to block the user to type non-existent tags ?, i'm using an ajax callback to return the list of available tags through the 'Source' variable, but the user is always available to type something new, i need to block that feature.

The issue is reproduced when typing a string and then pressing TAB.eg.:

76yduiskdjsdj TAB

that creates a new Tag, how to avoid that and just restrict to the values of the incoming drop down list ?

thanks

Get more data than just label

Hello,

I have tags ID and I would like to display tag label but post tag id.
How can I do ?

In examples I saw, only labels are available.

How can I do ?

Thank you

Store extra data (apart from label)

Is there a way to store extra data along with the tag coming from the tagSource?

I would like to present the user with a label coming from an AJAX call but actually store the id for that tag.

trigger onTagRemoved event after updating tags for singleField- Code attached

//this._trigger('onTagRemoved', null, tag); Need to trigger an event after the tag is updated

        if (this.options.singleField) {
            var tags = this.assignedTags();
            var removedTagLabel = this.tagLabel(tag);
            tags = $.grep(tags, function(el){
                return el != removedTagLabel;
            });
            this._updateSingleTagsField(tags);
        }

        this._trigger('onTagRemoved', null, tag);

Since, previously even though the tag is removed, the input text value still remains the same and gets updated on next tag removal only.

tag close gives firebug error

On close of selected tag, the click event closes tag but gives firebug error "f.easing[e.animatedProperties[this.prop]] is not a function".

Is there any solution to get the value in the text box if no triggers are applied?

I have an issue in the "tagit" plugin.

The tags are being generated while applying the trigger keys correctly. But my issue is, I have to convert the text in the textbox to a tag when i click a button, without using any trigger keys.

To be more clear:

  1. I have a text box which converts the texts to tags while applying trigger keys.
  2. I have a button which is used to save these tags.
  3. Now, after entering a text, without applying any trigger keys, when i click the button, that text should also be converted to a tag..so clicking the button would work simila as trigger...

How can this be implemented? Is there any way to implement this?

Thanks in advance.

Dexter

removeTag and add , how to call them out of tagit() method?

I'm using this plugin, i need to make controls on which tags are inserted before they are added and switch if control is ok i need to add if control is not ok i do not need to add the tag.

is this possible?

Also i would like to know if is possible to remove only 1 tag and not all tags at once

thx

Copy & Paste of Tags

Would it be possible to add some copy & paste capability to tag-it?
Within the input the "X" should be an image and a invisible comma should be added. Probably also quotes wrapping around each tag are necessary.
By adding some code in createTag (line 300) it would be possible to filter the input.

        var values = value.split(","); // here we need all configured separators and the behaviour of quotes
        if(values.length > 1){
            for(var i=0; i<values.length; i++){
                this.createTag(values[i],additionalClass);
            }
        }
        else{

new line in input created prematurely

Hello,

Not sure how to describe this other than just using pictures...

Notice there is more than enough room to type another tag, but if I do so, then the widget ends up looking like this (with the cursor on the new line):

Is there some option I'm missing or css that I'm doing incorrectly?

The way I'm using tag-it is simply creating a normal text input, putting the class "tagit" on it, then using jQuery's on document ready, $(".tagit").tagit().

I'm using the jQuery flick css theme as hosted by Google and I'm also using the lastest version of jQuery-ui as hosted by Google. jQuery is vesrion 1.6.2.

Thanks for the help.

"Uncaught RangeError: Maximum call stack size exceeded" using Tag-It with jquery 1.7.1

Hi,

My Tag-It code is simply this:

<form action="#">
            <fieldset>
                <div class="jqui clearfix">
                    <label>Experience in</label>
                    <div class="input">
                        <ul id="addr-select" class="fake-input" tabindex="1">
                        </ul>
                    </div>
                </div>
            </fieldset>
    </form>

<script type="text/javascript">

            $("#addr-select").tagit({
                 tagSource: function(search, showChoices) {
                    $.ajax({
                    url: "/autocomplete.php",
                    dataType: "json",
                data: search,
                success: function(choices) {
                    showChoices(choices);
                }
            });
            }
        });


    </script>

When I click in the fake input box, I get the following error message (in Chrome): "Uncaught RangeError: Maximum call stack size exceeded". (Firefox simply reports "too much recursion").

onTagAdded: allow rejecting a tag

This would allow implementing minLength/maxLength easily. When rejecting a tag the input field should not be cleared.

Right now you can only start a 0-second timeout to ensure the tag is removed after it has been added which is pretty ugly

Removed tag can't be re-added

If I add a tag, then remove it, it can't be re-added again. Here is my initialisation code:

$(selector).tagit({
    onTagAdded: function(event, tag) {
        draw_feed();
    },
    onTagRemoved: function(event, tag) {
        draw_feed();
    },
    allowSpaces: true,
    placeholderText: placeholder,               
    tagSource: function(search, showChoices) {
        $.ajax({
            url: "/tags/" + url + "/",
            data: {q: search.term},
            success: function(raw_return) {
                the_return = $.parseJSON(raw_return);
                showChoices(the_return.result);
            }
        });
    }           
});

HTML entities shown escaped in tag-it control

This is against Tag-it 2.0. This is possibly related to #48 although I couldn't quite understand that issue. If I initialize the tag-it control from a <ul> containing an html entity, the entity appears escaped in the control.

<ul>
<li>tag &amp; stuff</li>
<ul>

If I initialize the tagit control from this ul, then the tagit control will display &amp; instead of simply &. This is due to _create() using html() to get the contents of the <li>. I changed line 139 to use text() instead of html() and it solved the issue for me. The correction to line 139 is as follows:

that.createTag($(this).text(), $(this).attr('class'));

removeTag() by label

Right now you need a helper function that finds the DOM node of a tag if you want to remove a specific one. Would be better if there was a removeTagByName()-like function (actually, that's what I'd expected from the public removeTag function)

Allow double quotes

_cleanedInput removes the double quotes. For my needs I need it. Can be configurable?

Thanks.

valid xhtml

please add a close tag to the input fields (e. g. ) - otherwise it's not valid xhtml

Form data "forgotten" on page refresh

Usually when one refreshes a page with form data on it, Firefox remembers any data that has been entered. However, when tag-it is in use, all subsequent fields "forget" their previous state when refreshing the page.

For example. if I have a form with three input fields, "title", "tags" and "comments", and I enter some data into each field, then press refresh, Firefox will remember the title and tags that I have inserted, but not the comments.

I believe this is due to the fact that an additional input is added to the page for entering new tags, which must confuse the way Firefox remembers form data.

I think Firefox is the only browser that tries to remember form data when refreshing - but I could be wrong. I know this is a relatively trivial issue — I mean, if the other browsers forget form data, what does it matter if Firefox does likewise? — but if any radio buttons are used after the tag-it field, the wrong radio is checked when the page is reloaded, and if the user doesn't notice this they could submit incorrect data.

A rather un-elegant solution I have found for this is to insert <input type="text" style="display: none" class="tags-hidden-field" /> directly in the page's markup, then .remove() it using jQuery immediately after adding tag-it to the tags field. However, this doesn't really degrade gracefully. Is there another solution to this that I am overlooking?

Unescape escaped input

If for whatever reason tag-it gets its existing values as escaped strings-- which I must escape because they can come from a source other than tag-it and could contain quotes or html tags -- the createTag function should unescape these strings so they display correctly.

I've done this by adding value = $('<div/>').html(s).text(); to the top of the createTag function.

I don't think tag-it should be relying completely on the createTag function to create safe values, as those values can be modified by the user (e.g. with firebug) or could be modified elsewhere in the system (at least in my case).

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.