JSFiddle - React, Tailwind, and code Playground
by techunter
HTML
<div class="ui-widget">
<label for="tags">Tags:</label>
<input id="tags" />
</div>
JavaScript
$(document).ready(function () {
$("#tags").autocomplete({
source: function (request, response) {
$.ajax({
url: "/echo/jsonp",
dataType: "jsonp",
data: {
search: request.term,
result: ['opt1','opt2']
},
success: function (data) {
response($.map(data.result, function (item) {
return {
label: item.name,
value: item.name
}
}));
}
});
},
minLength: 2,
select: function (event, ui) {
console.log(ui.item ?
"Selected: " + ui.item.value + " aka " + ui.item.id :
"Nothing selected, input was " + this.value);
}
});
});