<input type="text" name="tags1" placeholder="Add Tags" id="tagmanager" autocomplete="off">
$('#tagmanager').tagmanager();
$('#tagmanager').tagmanager({ strategy: 'array', tagFieldName: 'tags[]', ajaxCreate: 'http://localhost/tag/create', ajaxRemove: 'http://localhost/tag/remove', initialCap: true, backspaceChars: [ 8 ], delimiterChars: [ 13, 44, 188 ], createHandler: function(tagManager, tag, isImport) { return; }, removeHandler: function(tagManager, tag, isEmpty) { return true; }, createElementHandler: function(tagManager, tagElement, isImport) { tagManager.$element.before(tagElement); }, validateHandler: function(tagManager, tag, isImport) { return tag; } });
Option Name | Datatype | Default | Description |
---|---|---|---|
strategy | string | array | The array strategy is default and creates a new input field for each tag created with the tag manager. The field name is defined with option tagFieldName and must be an array such as "tags[]". The second strategy is ajax which requires ajaxCreate and ajaxRemove options with URLs to post a tag to when created or removed. The third strategy is none which requires the programmer to use handlers to persist tags. |
tagFieldName | string | tags[] | When using the array strategy this option is required. This is the input field name for each tag to be sent back to your server as part of a form submission. |
ajaxCreate | string | null | A URL to post an ajax request to when a tag is created. e.g. http://localhost/tag/create?id=5 The createHandler can be used for more fine-grained ajax handling. |
ajaxRemove | string | null | A URL to post an ajax request to when a tag is removed/deleted. e.g. http://localhost/tag/remove?id=5 The removeHandler can be used for more fine-grained ajax handling. |
Option Name | Datatype | Default | Description |
---|---|---|---|
initialCap | boolean | true | Proper case the first word of each tag? |
backspaceChars | array | [ 8 ] | An array of character key codes to accept as "backspace" when the field is empty. When the input field is empty and a backspace character is entered the last tag will be removed. Pass an empty array the config to disable this feature. |
delimiterChars | array | [ 13, 44, 188 ] | An array of character key codes to delimit a tag. If char code 13, Enter Key, is in the list the default form submission mechanism is overridden to allow the enter key to act as a delimiter. |
Handler Name | Parameters | Description |
---|---|---|
createHandler | tagManager, tag, isImport | Fired when a new tag is created with the tag manager. Fired before createElementHandler. No return value. isImport will be true if fired from the populate method. |
removeHandler | tagManager, tag, isEmpty | Fired when a tag is removed from the tag manager. If the return value is true the tag will be removed. isEmpty will be true if fired from the empty method. |
createElementHandler | tagManager, jQuery element, isImport | When a tag is created in the manager this function will pass the genereated jQuery element as a parameter so it can be processed and placed anywhere on the page. isImport will be true if fired from the populate method. |
validateHandler | tagManager, tag, isImport | If the validator handler returns false the tag will not be created. If the validator handler returns any other value that value will be created instead of the original value. isImport will be true if fired from the populate method. |
Method Name | Handler | Can Cancel |
---|---|---|
create | validateHandler | yes |
create | createHandler | no |
create | createElementHandler | no |
remove | removeHandler | yes |
Method Name | Parameters | Description |
---|---|---|
create | tag, isImport | Adds a tag to the tag manager. The first parameter is the tag string. The second parameter defaults to false and will not fire ajaxCreate if true. |
remove | tagElement, isEmpty | Removes a tag from the tag manager. The first parameter is the jQuery handle of the tag span created from the tag manager. The second parameter defaults to false and will not fire ajaxRemove if true. |
populate | tags | Import an array of tags without firing ajaxCreate. |
empty | none | Clears all tags from the tag manager without firing ajaxRemove. |
pop | none | Pop the last tag. Used when backspace is fired. |
Field Name | Description |
---|---|
options | An object with the complete tag manager configuration. |
tagIds | An array of span ids of all tags in the tag manager. |
tagStrings | An array of tag strings of all tags in the tag manager. This array is paired with tagIds. A paired array approach is a simpler implementation than a hash. |