0

I try to make an autocomplete input, as I did sometimes in the past. But today I have to face a issue i can't really understand.

$( "#search_collab_autocomplete" ).autocomplete({
    appendTo :$('.form-add-new-user'),
    source : function(requete, response){
        $.ajax({
            url : $('.form-add-new-user').data('url'),
            dataType : 'json',
            data : {
                email : $('#search_collab_autocomplete').val(),
            },

            success : function(data){
                var arr = [];
                var i = 0;
                var fullObj = data;
                $.each(data, function(index, value){
                    var obj = {
                        id: index,
                        email: value,
                    };
                    arr[i] = obj;
                    i++;
                });
                response(arr, fullObj);
            },

            select: function( event, ui ) {
                console.log("hi");
            }
        });
    },
    minLength: 3
}).data( "ui-autocomplete" )._renderItem = function( ul, item ) {
    return $( "<li></li>" ).data("item.autocomplete", item)
        .append( "<a>"+item.email + "</a>")
        .appendTo( ul );
};

I have this code, which is partially workink because i can see list of result juste below my input field.

But when I click on / when I choose a item with keyboard I can't see nothing happening.. not even a simple console.log('hi');....

Am I using wrong select ?

4
  • Your items must be in [{label, value}] pairs within in your result data that is sent response() Commented May 2, 2018 at 0:53
  • Still, select event is never firing... Commented May 2, 2018 at 18:59
  • You may want to check that all syntax is correct. If no data or incorrect data is being passed to response() then no items can be shown and thus no items can be selected. This would prevent select event from firing. Commented May 7, 2018 at 17:16
  • But the whole autocomplete is working, i can use it. The only problem is this event that is not fired, I've found another way to achieve what I wanted.. Commented May 7, 2018 at 18:27

1 Answer 1

1

Your "select" is attached to $.ajax. It must be on the same level as "source" and "minLength".

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.