Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jquery ui autocomplete is automatically turned off

im using jquery ui to achieve autocomplete. mY code looks like this

$(function(){

$('input[name=store]').attr('autocomplete','on');

        $( "input[name=store]" ).autocomplete({
        source: function( request, response ) {
            //alert('hello');
            $.ajax({
                url: "http://localhost/dheeps/admin/calls/callback.php",
                dataType: "jsonp",
                data: {

                    sub:"searchstore",

                    store: request.term
                },
                success: function( data ) {
                    //alert('hello');
                    response( $.map( data.data, function( item ) {
                        //alert(item);
                        return {
                            label: item.name + (item.id1 ? ", " + item.adminName1 : "") + ", " + item.id,
                            value: item.id
                        }
                    }));

                }
            });
        },
        minLength: 2,
        select: function( event, ui ) {

        },
        open: function() {
            $( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" );
            //alert('helo');
        },
        close: function() {
            $( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" );
        }
    });

});

And the in the html of the form I found the input's element autocomplete attribute set to off. Is this why my code is not working. Please guide me

like image 873
user1400532 Avatar asked Jan 16 '23 10:01

user1400532


2 Answers

PUT BELOW

$('input[name=store]').attr('autocomplete','on');

AFTER THIS

 $( "input[name=store]" ).autocomplete({});

Because autocomplete attribute will added to element after initialization.

like image 58
Priyank Patel Avatar answered Jan 18 '23 22:01

Priyank Patel


Thanks for this info. This solved the problem. I think this is very odd that a simple test example works with no problem. Then, when I put it into a big project, it gets disabled automatically.

$(function () {
    var availableTags = ["One", "Two", "Three"];

    $("#myinput").autocomplete({
        source: availableTags
    });

    $("#myinput").attr('autocomplete', 'on');
});
like image 39
Arotae Avatar answered Jan 18 '23 23:01

Arotae