Leo
Leo

Reputation: 315

Disable autoselect on Autocomplete | jQuery UI

if i click the search button that search only '2018', but if I press enter button on pc that search '2018 songs' I want to search '2018' and if I press the enter button on pc, how I can fix it im using Autocomplete | jQuery UI

    var suggestCallBack;

document.addEventListener('DOMContentLoaded', function() {
$("#searchbox").autocomplete({
    source: function(request, response) {
        $.getJSON("http://suggestqueries.google.com/complete/search?callback=?",
            {
              "hl":"en", 
              "ds":"yt",
              "jsonp":"suggestCallBack",
              "q":request.term, 
              "client":"youtube" 
            }
        );
        suggestCallBack = function (data) {
            var suggestions = [];
            $.each(data[1], function(key, val) {
                suggestions.push({"value":val[0]});
            });
            suggestions.length = 10;
            response(suggestions);
        };
    },
    autoFocus: true,
    select: function(event, ui) {
                $(event.target).val(ui.item.value);
                $('#searchform').submit();
                return false;
            }
    });
});

enter image description here

in this case I want to search (2018) not (2018 songs) so how i have say before if I click on search button is ok I search (2018) but if I press enter button that search (2018 songs) how I can fix this?

Upvotes: 2

Views: 743

Answers (1)

James Garcia
James Garcia

Reputation: 186

Looks like the problem is the autoFocus: true you have in the autocomplete settings.

Looking at this docs, they say the key ENTER: "Select the currently focused item and close the menu".

I hope this may help.

Upvotes: 2

Related Questions