| 1 |
<!doctype html> |
| 2 |
|
| 3 |
<html lang="en"> |
| 4 |
<head> |
| 5 |
<meta charset="utf-8"> |
| 6 |
|
| 7 |
<title></title> |
| 8 |
<meta name="description" content=""> |
| 9 |
<meta name="author" content=""> |
| 10 |
|
| 11 |
<link rel="stylesheet" href="../src/jquery.typeahead.css"> |
| 12 |
|
| 13 |
<script src="http://code.jquery.com/jquery-2.1.0.min.js"></script> |
| 14 |
<script src="../src/jquery.typeahead.js"></script> |
| 15 |
|
| 16 |
</head> |
| 17 |
<body> |
| 18 |
|
| 19 |
<div style="width: 100%; max-width: 800px; margin: 0 auto;"> |
| 20 |
|
| 21 |
<h1>Newitem_v1 Demo</h1> |
| 22 |
|
| 23 |
<ul> |
| 24 |
<li> |
| 25 |
<a href="http://www.runningcoder.org/jquerytypeahead/documentation/">Documentation</a> |
| 26 |
</li> |
| 27 |
<li> |
| 28 |
<a href="http://www.runningcoder.org/jquerytypeahead/demo/">Demos</a> |
| 29 |
</li> |
| 30 |
</ul> |
| 31 |
|
| 32 |
<form> |
| 33 |
<div class="typeahead__container"> |
| 34 |
<div class="typeahead__field"> |
| 35 |
<div class="typeahead__query"> |
| 36 |
<input class="js-typeahead" |
| 37 |
name="q" |
| 38 |
autofocus |
| 39 |
autocomplete="off"> |
| 40 |
</div> |
| 41 |
<div class="typeahead__button"> |
| 42 |
<button type="submit"> |
| 43 |
<span class="typeahead__search-icon"></span> |
| 44 |
</button> |
| 45 |
</div> |
| 46 |
</div> |
| 47 |
</div> |
| 48 |
</form> |
| 49 |
|
| 50 |
<script> |
| 51 |
$.typeahead({ |
| 52 |
input: ".js-typeahead", |
| 53 |
minLength: 0, |
| 54 |
order: "asc", |
| 55 |
searchOnFocus: true, |
| 56 |
source: { |
| 57 |
groupName: { |
| 58 |
data: ['one', 'two', 'tree'] |
| 59 |
} |
| 60 |
}, |
| 61 |
template: function (query, item) { |
| 62 |
var template = '{{display}}'; |
| 63 |
if (item.addNewItem) { |
| 64 |
template = 'New Item'; |
| 65 |
} |
| 66 |
return template; |
| 67 |
}, |
| 68 |
callback: { |
| 69 |
onResult: function (node, query, result, resultCount, resultCountPerGroup) { |
| 70 |
result.push({ |
| 71 |
addNewItem: true, |
| 72 |
group: 'groupName' |
| 73 |
}); |
| 74 |
}, |
| 75 |
onClick: function (node, a, item, event) { |
| 76 |
if (item.addNewItem) { |
| 77 |
event.preventDefault(); |
| 78 |
alert('Create new item!') |
| 79 |
} |
| 80 |
} |
| 81 |
}, |
| 82 |
debug: true |
| 83 |
}); |
| 84 |
</script> |
| 85 |
|
| 86 |
</div> |
| 87 |
|
| 88 |
</body> |
| 89 |
</html> |