View on GitHub

Light-tag-handler

Light Tag Handler is a light jquery plugin, you can use it by import a js file and add some simple html code only.

Download this project as a .zip file Download this project as a tar.gz file

Let's try a demo first:

Let input a list of words and separate by comma at the text input box shown below, for example, you can input something like : apply,mango,pear, (<- type them, but not copy and paste) to type:

An input box with initial value "1,2,3,4,5,6":
An input box with initial value "x,y,z":
An empty input box:



*Remark: if you input something wrong and what to remove the existing tags, you can simply click on the tag to remove it.


Browser Supported

  • - Internet Explorer 9 +
  • - Google Chrome
  • - FireFox

How to make it works ?

1) Import Javascript file

Import the jQuery file and lth_jquery.js (or the modified javascript file lth_jquery.min.js) first

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript" src="lth_jquery.js"></script>

2) Import Javascript file

Add a text input with class "lth_hidden" placing in a div tag with lth_group class.

<div class="lth_group">
    <input type="text" name="demo_3" class="lth_hidden" />
</div>

If your page get more than one text input box with tag handler, you can just copy a few more set of the html shown above and edit the name attribute value (for example: demo_3) to make it works. The html code of the demonstration example in this page is shown below:

<div class="lth_group">
    <input type="text" name="demo_1" class="lth_hidden" value="1,2,3,4,5,6" />
</div>
<div class="lth_group">
    <input type="text" name="demo_2" class="lth_hidden" value="x,y,z" />
</div>
<div class="lth_group">
    <input type="text" name="demo_3" class="lth_hidden" />
</div>

Input string and output string example

Input stringOutput stringDescription
"aaa"""nothing
"aaa,""aaa"
"a,b,c""a,b"
"a,b,c,""a,b,c"
" ,"""Enter space and comma, get nothing and won't make any tag
",a, ,b,,""a,b"Would remove all empty tag in output string.
"apply, mango, pear,""apply,mango,pear"This plugin would remove all space next to commas.


Update

26-11-2014
Make inline style to valuable.
Config Style.
25-11-2014
Add instruction and demonstration page.
24-11-2014
Ligth tag handler v1.0 release


Reference

http://stackoverflow.com/questions/1481152/how-to-detect-a-textboxs-content-has-changed
http://stackoverflow.com/questions/15013848/jquery-get-value-of-previous-input-text-field