跳至内容
菜单
此问题已终结

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.


形象
丢弃
最佳答案

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.

形象
丢弃
相关帖文 回复 查看 活动
1
6月 24
2356
0
2月 24
1005
1
5月 25
1774
0
7月 24
256
1
9月 23
1684