Coder Social home page Coder Social logo

underovsky / jquery-tagsinput-revisited Goto Github PK

View Code? Open in Web Editor NEW
63.0 6.0 29.0 121 KB

Revisited version of popular jQuery Tags Input Plugin

License: MIT License

JavaScript 70.95% HTML 16.94% CSS 12.11%
jquery jquery-tags jquery-plugin tag-input

jquery-tagsinput-revisited's Introduction

Release

jQuery Tags Input Revisited Plugin

Basic information

Forked from a discontinued jQuery Tags Input Plugin created by XOXCO.

See the original project here: https://github.com/xoxco/jQuery-Tags-Input

jQuery Tags Input Revisited Plugin is an improved and fixed version of the previous plugin. It's also adjusted to match the current web standards.

Simple tag editing written in jQuery.

Original description: Do you use tags to organize content on your site? This plugin will turn your boring tag list into a magical input that turns each tag into a style-able object with its own delete link. The plugin handles all the data - your form just sees a comma-delimited list of tags!

Live example

You can see plugin live example here.

Improvements

jQuery Tags Input Revisited welcomes few very important improvements:

  1. It switches input width adjustment from JS to flexbox.
  2. It manipulates styles with CSS not JS.
  3. It uses standard placeholder instead of input value.
  4. It uses CSS for remove link not text.
  5. It adds better validation for min/max string length, tags limit and pattern validation.
  6. It uses CSS matching current standards.
  7. It adds copy/paste mechanism that automatically splits the string into tags.

Usage

Add the Javascript and CSS files to the HTML. You can use regular or minified files. Style the tags however you want.

<script src="jquery.tagsinput-revisited.js"></script>
<link rel="stylesheet" type="text/css" href="jquery.tagsinput-revisited.css">

Create a real input in your form that will contain a delimiter-separated (by standard it's a comma) list of tags. You can put any default or existing tags in the value attribute, and they'll be handled properly.

<input name="tags" id="tags" class="tagsinput" value="foo,bar,baz">

Then, simply call the tagsInput function on any field that should be treated as a list of tags.

$('.tagsinput').tagsInput();

If you want to use jQuery.autocomplete, you can pass an object with autocomplete options (https://jqueryui.com/autocomplete/).

$('.tagsinput').tagsInput({
  autocomplete: {option: value, option: value}
});

You can add and remove tags by calling the addTag() and removeTag() functions.

$('.tagsinput#tags').addTag('foo');
$('.tagsinput#tags').removeTag('bar');

You can import a list of tags using the importTags() function.

$('.tagsinput#tags').importTags('foo, bar, baz');

You can also use importTags() to reset the tag list.

$('.tagsinput#tags').importTags('');

And you can check if a tag exists using tagExist().

$('.tagsinput#tags').tagExist('foo')) { ... }

If additional functionality is required when a tag is added or removed, you may specify callback functions via the onAddTag and onRemoveTag parameters. Both functions should accept a single tag as the parameter.

If you do not want to provide a way to add tags, or you would prefer to provide an alternate interface for adding tags to the box, you may pass an false into the optional interactive parameter. The tags will still be rendered as per usual, and the addTag and removeTag functions will operate as expected.

If you want a function to be called every time a tag is updated/deleted, set it as the onChange option.

By default, if the cursor is immediately after a tag, hitting backspace will delete that tag. If you want to override this, set the removeWithBackspace option to false.

For validation purposes you can use unique, limit, minChars, maxChars, whitelist and validationPattern parameters.

You can check example.html file to see the plugin usage examples.

Options

$('.tagsinput#tags').tagsInput({
  interactive: true,
  placeholder: 'Add a tag',
  minChars: 2,
  maxChars: 20, // if not provided there is no limit
  limit: 5, // if not provided there is no limit
  validationPattern: new RegExp('^[a-zA-Z]+$'), // a pattern you can use to validate the input
  width: '300px', // standard option is 'auto'
  height: '100px', // standard option is 'auto'
  autocomplete: { option: value, option: value},
  hide: true,
  delimiter: [',',';'], // or a string with a single delimiter
  unique: true,
  removeWithBackspace: true,
  whitelist: [], // null or aray of whitelisted values
  onAddTag: callback_function,
  onRemoveTag: callback_function,
  onChange: callback_function
});

About the author

License

The MIT License (MIT)

Copyright (c) 2017 Krzysztof Rusnarczyk

jquery-tagsinput-revisited's People

Contributors

aha00a avatar bensmithett avatar cboden avatar erlend avatar exside avatar jaylevitt avatar kkirsche avatar lucknerjb avatar marioestrada avatar mariooc avatar maxooo avatar melkorm avatar prymitive avatar punytan avatar sebm avatar therabidbanana avatar tybulewicz avatar underovsky avatar vgichar avatar xorrizon 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

jquery-tagsinput-revisited's Issues

Bug remove item

I enter another input, the tags will be removed each item

Cannot read property 'autocomplete' of undefined

I have been facing the error Cannot read property 'autocomplete' of undefined only in case if I have another autocomplete/select2 field in same page.

But it was fine after following update
Please update following change

if (jQuery.ui.autocomplete !== undefined)
to
if (jQuery.ui && jQuery.ui.autocomplete !== undefined)

why is element id changed if delimiter specified?

I called ajax function which replaced dialog contents. Tags are used in this dialog. Tagsinput replaces my ids when called repeatedly.

Why is element id changed if delimiter specified? It changes my element identification.

Is there a method to destroy Tagsinput intertnal data when elements are replaced?

Thanks

`
$.fn.tagsInput = function(options) {
...
var id = $(this).attr('id');
if (!id || _getDelimiter(delimiter[$(this).attr('id')])) {
id = $(this).attr('id', 'tags' + new Date().getTime() + (++uniqueIdCounter)).attr('id');
}

`

Tags can be unintentionally removed

When a tag is being removed under certain conditions, other tags can be accidentally removed. This appears to be due to i not being redeclared in the scope of each for loop in a few places

Use script after append

Hello,

I am facing problems to use the script after $('#id').append(html);

this generates new input. So when I call the script after this input is added it does not work.

Calling the script as:

$.getScript("../js/jquery.tagsinput-revisited.js", function(){
});

input.tag-input (and wrapping div) missing after tag delete

when I delete a tag input.tag-input and wrapping div disappears. I have no idea what I do wrong. I use the last version.
I use Bootstrap v3.3.7, Query v3.1.1 and Query UI - v1.12.1
`
$(kontaktElems).tagsInput({
// allows new tags
interactive: true,
// custom placeholder
placeholder: '',
// width/height
width: 'auto',
height: 'auto',
// hides the regular input field
hide: true,
// custom delimiter
delimiter: ';',
// duplicate validation
//unique: true,
// removes tags with backspace
removeWithBackspace: true,
// an array of whitelisted values
whitelist: null,
});

`

Slow autocomplete

I would use your lib for multiple select but the autocompletion is too slow (takes a fraction of seconds)

Autocomplete to take key-value pair using ajax call

I want my autocomplete tags to be obtained from ajax call which gives me a key value list. It should show value in dropdown but on selection it should allow me to capture its key as well like the select functionality.
Note: Also if the value is not found in my ajax call, it should allow me to create the tag, in this case I will create a new tag and use its ID(key)

Library is broken for m1 macs

When I received a new laptop, one of the web sites that uses this library was broken for me in a weird way. After some research I concluded that the issue was when id's for labels are generated, multiple could be generated with same id's since it is based on timestamps. Then I concluded that this happens exclusively for new apple ARM chip users.

Demo

Please provide a link to the demo.

Display tags from SQL

I've called and I can show the tags on my form by calling them with php inside the value.
The problem is, it shows only the first 2 and only if I delete one of them, the other "show up".

EDIT:
Never mind - My mistake - I accidentally forgot to call the correct page id so only the autocomplete options loaded...
Stupid me...

Make tags draggable

It would be really useful if the tags could be dragged to re-order them within their parent box (and this would then obviously be reflected in the form element).

Add custom data...

One feature that would be very useful to me would be to add the current date along with the typed text. I use it to track system changes.
Example:
image

Any idea?

License file

The jquery-tagsinput-revisited/src/jquery.tagsinput.js file states that this project is under MIT license.

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.