Disable select2 plugin in JQuery dropdown

风流意气都作罢 提交于 2019-12-07 15:07:20
Jay Rizzi

From the select2 docs

In case that you need to disable certain options so that they can't be selected by the select2 interface, you can now pass in disabled: true with your data. Please note: This also works for incoming values from ajax. When attached to a element, Select2 will respect its elements' disabled property.

$( document ).ready( function() {
    $( '#e24' ).select2( {
        query: function( query ) {
            var data = {
                results: [
                    { id: 1, text: "I'm selectable" },
                    { id: 2, text: "I'm a disabled option", disabled: true },
                    { id: 3, text: "I'm selectable too!" }
                ]
            };

            query.callback( data );
        }
    } );
} ); 
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!