Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

viappio's avatar

Select2 click on item not working

I have a laravel project where i need an autocomplete select that call an API for results. For the frontend task i use Select2 plugin:

                $('#userAutoComplete').select2({
                    placeholder: 'Select an user',
                    allowClear: true,
                    ajax: {
                        type:'POST',
                        url: path,
                        dataType: 'json',
                        delay: 250,
                        processResults: function (data) {
                            return {
                                results:  $.map(data.original, function (user) {
                                    return {
                                        text: user.lastname + " " +user.firstname +" ("+user.email+")",
                                        id: user.id
                                    }
                                })
                            };
                        },
                        cache: false
                    }
                });

This works well while retrieving the results, but then when the dropdown is populated, when i click any option, nothing happens, also hover is not working (not changing color on the results as i hover with the mouse). Also no errors in the console. Im pretty much confused

0 likes
1 reply
viappio's avatar
viappio
OP
Best Answer
Level 1

For the foture me XD : The id field was mismatched BE side (Id (capital I) instead of id). So the field was not found by the plugin. If that happens the select event isn't fired. No error in the console whatsoever. Pretty Meh.

Please or to participate in this conversation.