tags input autocomplete ajax - Download Dynamic Tags Input With Autocomplete Using AJAX

Download Dynamic Tags Input With Autocomplete Using AJAX

Posted on

This time I will share jQuery Plugin and tutorial about Dynamic Tags Input With Autocomplete Using AJAX, hope it will help you in programming stack.

tags input autocomplete ajax - Download Dynamic Tags Input With Autocomplete Using AJAX
File Size: 6.37 KB
Views Total: 5061
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   

A lightweight and dynamic jQuery tags input plugin that allows the user to type multiple items as tags or select tags from a suggestion list as they type.

How to use it:

1. Load the stylesheet tags.css and JavaScript tags.js in the html document.

1 <link href="tags.css" rel="stylesheet">
2 <script src="jquery.min.js"></script>
3 <script src="tags.js"></script>

2. Create a set of pre-selected tags as follows (optional):

1 <span class="data">
2   <span class="tag">
3     <span class="text" _value="jquery">jQuery</span>
4     <span class="close">&times;</span></span>
5   <span class="tag">
6     <span class="text" _value="script">Script</span>
7     <span class="close">&times;</span>
8   </span>
9 </span>

3. Create the html for the suggestion list.

1 <span class="autocomplete">
2   <input type="text" />
3     <div class="autocomplete-items">
4     </div>
5 </span>

4. Wrap them into the tags input container.

01 <div class="tags-input" id="myTags">
02   <span class="data">
03     <span class="tag">
04       <span class="text" _value="jquery">jQuery</span>
05       <span class="close">&times;</span></span>
06     <span class="tag">
07       <span class="text" _value="script">Script</span>
08       <span class="close">&times;</span>
09     </span>
10   </span>
11   <span class="autocomplete">
12     <input type="text" />
13       <div class="autocomplete-items">
14       </div>
15   </span>
16 </div>

5. Define your own suggestions in a JSON file.

1 // data.json
2 [
3   {"name": "JavaScript","id": 1},
4   {"name": "HTML5","id": 2},
5   {"name": "CSS3","id": 3},
6   {"name": "CSSScript","id": 4}
7 ]

6. Populate the suggestion list using AJAX requests.

01 let sug_area=$(element).parents().eq(2).find('.autocomplete .autocomplete-items');
02   $.getJSON("data.json", function( data ) {
03     _tag_input_suggestions_data = data;
04     $.each(data,function (key,value) {
05       let template = $("<div>"+value.name+"</div>").hide()
06       sug_area.append(template)
07       template.show()
08     })
09   });
10 }

This awesome jQuery plugin is developed by neveresthub. For more Advanced Usages, please check the demo page or visit the official website.

source : jquery.net