personal-book/app/views/admin/books/_author_autocomplete.html.erb

33 lines
1.1 KiB
Plaintext
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<script type="text/javascript">
var map = {},
members = [],
data = <%= raw @members_data %>;
$.each(data, function (i, member) {
map[member.memberName] = member;
members.push(member.memberName);
});
$(document).ready(function(){
$('#member_autocomplete').typeahead({
source: function (query, process) {
return members;
},
updater: function (item) {
selectedMember = map[item].memberId;
$('#member_value').val(selectedMember);
return item;
},
matcher: function (item) {
if (item.toLowerCase().indexOf(this.query.trim().toLowerCase()) != -1) {
        return true;
      }
},
sorter: function (items) {
    return items.sort();
},
highlighter: function (item) {
var regex = new RegExp( '(' + this.query + ')', 'gi' );
return item.replace( regex, "<strong>$1</strong>" );
},
});
});
</script>