How to Adding OPAC Autocomplete Search Feature in Koha.

OPAC that can be easily implemented auto-completion, would be a great and much wanted feature to have. using the OpacUserJs system preference.

Go to: Koha Administration > Global System Preferences > OPAC > OPACUserJS

Copy and Paste the following Javascript.

/**Autocomplete Search**/
$(document).ready(function(){
$("#translControl1").autocomplete({
        source: function(request, response) {
            $.ajax({
                url: "https://en.wikipedia.org/w/api.php",
                dataType: "jsonp",
                data: {
                    'action': "opensearch",
                    'format': "json",
                    'search': request.term
                },
                success: function(data) {
                    response(data[1]);
                }
            });
        },
        open: function() {
            $('.ui-autocomplete');
       }
    });
});

Reference
Wikipedia : https://en.wikipedia.org/w/api.php
koha-community: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=25532#c15

Post a Comment

2 Comments