The element that looks like <input>
is actually <div>
, <input>
is inside it, and the tags that appear are divs inserted with document.createElement
. Autocomplete (when typing) is really a question of using ajax and interacting with the server.
However the problem seems to me only with the front end itself, so there are plugins ready that can help.
jQuery
For jQuery there are several plugins, but I'll quote the link :
Add this to the page:
<script src="jquery.tagsinput.js"></script>
<link rel="stylesheet" type="text/css" href="jquery.tagsinput.css" />
Create an element like this:
<input name="tags" id="tags" value="foo,bar,baz" />
Put in $.ready
or $(...)
this:
$(function() {
$('#tags').tagsInput();
})
It supports interaction with the server like this:
$('#tags').tagsInput({
autocomplete_url:'http://myserver.com/api/autocomplete'
});
Basic example:
$(function() {
$('#tag1').tagsInput({});
});
<link href="http://xoxco.com/examples/jquery.tagsinput.css" rel="stylesheet"/>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script><scriptsrc="http://xoxco.com/examples/jquery.tagsinput.js"></script>
<div id="wrapper">
<p>Exemplo básico:
<input id="tag1" value="stack,overflow,portugues,olá,mundo" />
</p>
</div>
Angular.js
For angular there is link :
Add after angular.js:
<script type="text/javascript" src="path/to/angular.min.js"></script>
<script type="text/javascript" src="path/to/ng-tags-input.min.js"></script>
No header add:
<link rel="stylesheet" href="path/to/ng-tags-input.min.css">
Add application:
angular.module('myApp', ['ngTagsInput']);
To use:
<tags-input ng-model="tags"></tags-input>