Skip to content

Instantly share code, notes, and snippets.

@cornernote
Created June 15, 2015 00:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cornernote/e6d1f3ce3f4983a73d89 to your computer and use it in GitHub Desktop.
Save cornernote/e6d1f3ce3f4983a73d89 to your computer and use it in GitHub Desktop.
select2 with free-text
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<link href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.0/css/select2.min.css" rel="stylesheet">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.0/js/select2.min.js"></script>
<title>Select 2</title>
</head>
<body>
<form>
<select id="e1">
<option value="1">Awsome</option>
<option value="2">Cool</option>
<option value="3">Balls</option>
</select>
</form>
<script>
$('#e1').select2({
multiple: false,
tags: true,
createTag: function (tag) {
return {id: tag.term, text: tag.term, tag: true};
}
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment