select2 default value for single field -
I'm using for my project when the page loads, I want to have a default value in an input field . I tried to set it to initSelection
, while I'm starting select2 component like this.
$ (document) .ready (function () {allowClear: true, ajax: {// instead we use functional assistant data of selection 2 to write the function to write the function For: 'json', url: "public / data.php", data: function (word, page) {return {q: word, /. ("# City") .val (), child_value: ""} }}, "Map", all_selected: $ ("#map-all") halcus ("active"), original_man: result: work (data, page) {// parsing in the expected format by selection 2. // when We are using custom formatting function, we Remote JSON data returns are not required to change (result: data);}}, initSelection: function (element, callback) {return $ .getJSON ("public / data.php? Q =" + element.val () + "& Amp; component = map & amp; all_selected = false & parent_value = & amp; child_value =", blank, function (data) {if ($ .isFunction (callback)) {return callback (data);}}) ;}, FormatSelection: format, formatResult: format,});
However this does not work because it should be.
However, when I multiple : True,
as a select2 option, it works perfectly How can I do this for a hidden area?
Thanks & amp; Regards!
OK, I solved it by changing callback from return callback (data);
to return callback (data [0]);
I think the reason behind this is that the field is not a multiple area, it accepts only one object for the callback function.
Comments
Post a Comment