I am getting the values from json and displaying it in a popup. I need to disable that option which i am getting from json. How can i do that?
I tried normal jQuery but It doesn't work. I tried disabled true that also not working.
Please give solution.
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 ); } } ); } );