jquery-select2

AngularUI select2 onChange method

戏子无情 提交于 2019-12-06 23:40:54
How do I go about doing something along these lines: <select ui-select2 multiple="true" on-change="onChange()" data-ng-model="select2Model"></select> where in my controller, I have the onChange(select2OnChangeData) defined. I tried adding this scope: { model: "=ngModel", onChange: "&onChange" }, to angular-ui, but that changed the scope variable and broke the rest of the functionality. I'd really like to refrain from doing: .on("change", function(e) Good thing I did just this in my project: HTML <select data-placeholder="Select an asset" class="input-xxlarge" ui-select2="sourceAssetId" ng

How can Select2 dropdown load results via AJAX

北城余情 提交于 2019-12-06 21:48:36
问题 I've got a simple select2 box which loads a dropdown menu. But what's the best way to reload the dropdown menu each time the select menu is opened with the results of an AJAX call? The ajax call would return <option value=1> <option value=2> and so on I've look through the AJAX examples on the select2 docs but it looks a little overcomplicated for what I need. TIA 回答1: Assume u have html <p> Hidden field value set in the following format: <br /> <em>'34:Donnie Darko,54:Heat,27:No Country for

Select2 generating id with ajax response data

时间秒杀一切 提交于 2019-12-06 21:46:33
My JSON response data does not contain an ID field, which is required by Select2 in order to display results. In the documentation they provide a way to generate id, however, I was unable to do so. Can someone provide an example on how to do this? I have tried this so far: $('.itemSearch').select2( ajax: { type: "POST", url: '/Default.aspx/TestMethod', data: function(params){ var query={ message:params.term } return JSON.stringify(query); }, processResults: function (data) { var data1 = $.map(data, function (obj) { obj.id = obj.id || obj.ItemNumber; // replace pk with your identifier return

Angular UI Select2, why does ng-model get set as JSON string?

痞子三分冷 提交于 2019-12-06 21:41:24
问题 I'm using angular-ui's select2 for a fairly simple dropdown. It's backed by a static array of data sitting on my controller's scope. In my controller I have a function that gets called on ng-change of the dropdown so that I can perform some actions when the value changes. However, what I'm finding is that the ng-model's property gets set as a JSON string rather than an actual javascript object, which makes it impossible to use dot notation to grab properties off of that model. Here's the

Prevent select2 from autmatically focussing its search-input when dropdown is opened

心已入冬 提交于 2019-12-06 21:20:07
问题 I'm looking for a way to prevent select2's search-input being automatically focussed when the select2-dropdown is opened. I know this is select2's intended default behavior - and while this is fine for desktop clients, I need to prevent this behavior for the iPad where it triggers the iPads software keyboard, which is not what we want as a default. I've searched for an option to do so with no luck. http://jsfiddle.net/KwW5n/2/ reflects our setup - we're using a simple -element as a base for

How to clone select2 v4 Ajax

北城余情 提交于 2019-12-06 20:16:43
I am attempting to do an AJAX call with the Select2 ver4 jquery plugin and Using Loading remote data of Select2 sample page I am trying to clone a select which contains select2 tool. But select2 dropdown disabled when cloning. HTML CODE <tr> <td> <select class="js-example-data-ajax" id="sel1"> </select> <button type="button" class="addline">Add Line</button> </td> </tr> jQuery CODE $.fn.select2.amd.require( ["select2/core", "select2/utils", "select2/compat/matcher"], function (Select2, Utils, oldMatcher) { var $ajax = $(".js-example-data-ajax"); function formatRepo (repo) { if (repo.loading)

Select2 with Ajax is not sending request

耗尽温柔 提交于 2019-12-06 19:27:10
问题 I'm using Select2 version 4.0.0 and trying to load a remote JSON from a PHP script that returns the already formated data that I need. The problem is that the forces of the darkness are making something, because I just can't send the request, there is no error, but there is no request sent, it just stays so quiet as a devil that I'm almost crying! I'm using LiveScript and Jade as alternatives to JavaScript and HTML, but I'll translate'em here. First, my markup defines the selectable field:

Select2 - make it readonly (not disabled!) from js

主宰稳场 提交于 2019-12-06 18:37:49
问题 How can I dynamically make a select2 combobox read-only? Here's what I've tried so far: $('...').attr({'readonly': 'readonly'}).trigger('change.select2'); $('...').attr({'readonly': 'readonly'}).trigger('change'); $('...').select2().enable(false); 回答1: See: http://select2.github.io/select2/ I did it with: $("#modelname-fieldname").select2({disabled:readonly}); Where: modelname-fieldname is as in: $form -> field($modelname, "fieldname") -> widget(Select2::classname(), [ ... ]); readonly is

jQuery form repeater and select2 dont work together

可紊 提交于 2019-12-06 16:22:02
I am using Select2 and jQuery form repeater ( https://github.com/DubFriend/jquery.repeater ) I have searched on google/so for 2 days, but cant seem to get it to work. include jquery/select2.js/jquery.repeater.js var form = $('#form'); form.find('select').select2(); form.repeater({ show: function () { $(this).show(function(){ form.find('select').select2('destroy').select2(); }); }, hide: function (remove) { $(this).hide(remove); } }); The problem is the jQuery.repeater clones the div tag in which the input and select elements are when select2 is already initialized and has already changed the

Styling individual select2 tags

烈酒焚心 提交于 2019-12-06 16:07:59
I'm trying to style individual select2 tags using Bootstrap's button styles ( .btn-primary and .btn-danger ) based on if the user created a tag (applying the red .btn-danger style) or if the user selected a existing tag (applying the blue .btn-primary style. I've tried to apply the style during the select event (select2:select) event: $("#ticker_select").on('select2:select', function(e) { // If the e.params.data.id equals e.params.data.txt, // then it is a user-created tag! if (e.params.data.id == e.params.data.text) { // User-created tag; Mark the tag red $(".select2-selection__choice[title='