javascript - select2 atribute "data-init-text" -
i populate select, not have associated description. have value.
i using (select2):
$( '#element' ).attr( "data-init-text", "" ).val( value ).change(); but not work because have no description
i'm using hidden input ajax call.
any idea. thank you
you need text (which call description) id (which call value). since using ajax select2 data, use ajax call text id.
you supply initselection function makes ajax call. might this:
initselection: function(element, callback) { var id= $(element).val(); if (id) { $.ajax('/this/is/the/url/', { data: { id: id }, datatype: 'json', success: function(data) { callback(data); } }); } } in case ajax call passes "id" parameter , expected return json looks this:
{ id: 'the_passed_in_id', text: 'the_text_for_the_id' }
Comments
Post a Comment