javascript - formatSelection not working in select2.js -
i using select2.js populate field multiple values using ajax call.
below code using.
html
<input id="id_test_name" class="form-control">
script
<script type="text/javascript"> $("#id_test_name").select2({ placeholder: "search item", minimuminputlength: 2, ajax: { url: "/resourse/?format=json&name=xyz", datatype: 'json', quietmillis: 100, data: function (term, page) { return { option: term }; }, results: function (data, page) { return { results: $.map(data.results, function (item) { return { name: item.name, abbreviation: item.abbreviation, id: item.id } }) }; } }, formatresult: function (data, term) { return data.name + '(' + data.abbreviation +')'; }, formatselection: function (data) { return data.name + '(' + data.abbreviation +')'; }, dropdowncssclass: "bigdrop", escapemarkup: function (m) { return m; } }); </script>
results populating in dropdown not able select populated results, not able find doing wrong?
also need id of selected results in other(hidden) field.
update: jsfiddle: http://jsfiddle.net/n5phohov/2
Comments
Post a Comment