Coder Social home page Coder Social logo

tags's Introduction

Tag input

A nice, intuitive tag input plugin for jQuery, which degrades gracefully, when Javascript is disabled and is applied to a simple text input – no fancy HTML required.

This plugin has been created for Zootool: http://zootool.com and the Kirby CMS: http://getkirby.com

Demo:

http://getkirby.com/blog/panel-tags-field/demo

Features

  • full keyboard navigation
  • autocompletion
  • support for local json data or remote requests
  • automatic duplication avoidance

Usage

Include jquery, the tag input script and the stylesheet

<link rel="stylesheet" href="/path/to/css/tags.css" type="text/css" />

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.8/jquery.min.js"></script>
<script src="/path/to/js/tags.js"></script>

Create the input

<input type="text" id="tags" name="tags" />

Initialize the plugin

<script>
	$(function() {
		$('#tags').tagbox({
			url: '/path/to/your/tags/json'
		})
	});
</script>

Options

url:

Can be either the URL to a server side script, which provides a simple json encoded array of tags – coming from a DB for example. Or it can be a json encode local array, which is perfect if you don't have too many tags and it's ok to add them directly to the same page.

lowercase (default = true)

Convert all tags to lowercase.

duplicates (default = false)

Set this to true if you want to allow duplicate tags.

separator (default = ',')

Define the separating character

minLength (default = 1)

Define the minimum allowed length of tags

maxLength (default = 140)

Define the maximum allowed length of tags

classname (default = 'tagbox')

Define the css selector for the main tag box element

valid(tag)

Define a function to validate the tag. Must return a boolean

Events

onAdd(tag)

Will be triggered when a new tag is added

onRemove(tag)

Will be triggered when a tag has been removed

onDuplicate(tag)

Will be triggered when a user tries to add a duplicate tag

onInvalid(tag)

Will be triggered when a user tries to add an invalid tag. To identify the type of error can use this.errorType.

Example:

onInvalid: function(tag){
	if( this.errorType == 'badLength' ){
		// Your code...
	}
}

When the tag length be greater than option.maxLength or less than option.minLength the errorType be set to 'badLength'.

onReady()

Will be triggered when all tags have been loaded for autocompletion

Adding initial tags

You can simple add tags to the input field like this:

<input type="text" id="tags" name="tags" value="design, architecture, photography" />

…which will by automatically converted to proper tag elements on load.

Todo:

I believe that the plugin can be written in a more modern jQuery-way. I never dived too deep into plugin development for jQuery. So if you want to give it a look and convert a few things here and there I'd be very happy :)

License:

MIT License - http://www.opensource.org/licenses/mit-license.php

tags's People

Contributors

bastianallgeier avatar maxidr avatar

Watchers

 avatar  avatar

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.