This commit is contained in:
James Cole
2018-09-30 19:11:49 +02:00
parent d4c763df84
commit e50641e969
2 changed files with 38 additions and 43 deletions

View File

@@ -25,41 +25,37 @@ $(function () {
var transactions = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
identify: function (obj) {
return obj.id;
},
prefetch: {
url: autoCompleteUri,
filter: function (list) {
return $.map(list, function (name) {
return {name: name.name};
});
}
url: autoCompleteUri
// filter: function (list) {
// return $.map(list, function (name) {
// return {name: name.name};
// });
// }
},
remote: {
url: autoCompleteUri + '?search=%QUERY',
wildcard: '%QUERY',
filter: function (list) {
return $.map(list, function (name) {
return {name: name.name};
});
}
wildcard: '%QUERY'
// filter: function (list) {
// return $.map(list, function (name) {
// return {name: name.name};
// });
// }
}
});
transactions.initialize();
var input=$("#link_other");
var input = $("#link_other");
input.typeahead({hint: true, highlight: true,}, {source: transactions, displayKey: 'name', autoSelect: false});
input.change(function () {
var current = input.typeahead("getActive");
if (current) {
// Some item from your model is active!
if (current.name.toLowerCase() ===
input.val().toLowerCase()) {
// This means the exact match is found. Use toLowerCase() if you want case insensitive match.
$('input[name="link_journal_id"]').val(current.id);
} else {
$('input[name="link_journal_id"]').val(0);
}
} else {
$('input[name="link_journal_id"]').val(0);
}
});
input.bind('typeahead:select', function (ev, suggestion) {
console.log('Selection: ' + suggestion.name);
if (suggestion.name.toLowerCase() === input.val().toLowerCase()) {
// This means the exact match is found. Use toLowerCase() if you want case insensitive match.
$('input[name="link_journal_id"]').val(suggestion.id);
} else {
$('input[name="link_journal_id"]').val(0);
}
});
});