Skip to Content
Menu
This question has been flagged

Hello everyone, 

I'm grappling with an issue involving a select box in a web form that utilizes Select2 with Ajax remote data (https://select2.org/data-sources/ajax) to search for partners in Odoo 16 Website. The stumbling block is the error I'm currently facing:

  Uncaught Javascript Error > Option 'ajax' is not allowed for Select2 when attached to a select element.

 

JS Code:
$(document).ready(function() {

    $("#partner_select").select2({
        ajax: {
            url: '/ms_om/get_partner_names',
            dataType: 'json',
            delay: 250,
            data: function(params) {
                return {
                    search: params.term,
                    type: 'partner_search',
                };
            },
            processResults: function(data) {
                return {
                    results: $.map(data, function(partner) {
                        return {
                            id: partner.id,
                            text: partner.name,
                        };
                    }),
                };
            },
        },
        cache: true,
        placeholder: 'Search for a partner',
        minimumInputLength: 3,
    });

});

 Template: 


Any ideas on how to fix this? It's crucial for my web form project. Your insights would be a game-changer!

Thanks a bunch.


Avatar
Discard
Best Answer

In order to use a select2 with dynamic download, you have to use an input, not a select/option.

Indeed, your select2 needs to know what the user is typing.

Avatar
Discard
Related Posts Replies Views Activity
1
Jun 24
1915
0
Feb 24
765
1
May 25
1168
0
Jul 24
256
1
Sep 23
1394