jquery-select2

$watch not firing on data change

喜你入骨 提交于 2019-11-27 12:38:23
问题 I have a watch setup against the model of a ui-select2 dropdown (from ui-bootstrap). The watch fires on load but not on data changes and I can't figure out why. It isn't the usual problem of not $apply'ing the model change or not using the third parameter for equality comparison (at least from my code). What do I need to do to get it to fire? Here is a plunk demonstrating the issue. 回答1: I fixed some stuff. http://plnkr.co/edit/5Zaln7QT2gETVcGiMdoW?p=preview The JS var myMod = angular.module(

Dynamically add item to jQuery Select2 control that uses AJAX

孤街浪徒 提交于 2019-11-27 12:17:57
I have a jQuery Select2 control that uses AJAX to populate: <input type="text" name="select2" id="select2" style='width:400px' value="999"> var initialSelection = { id: '999', text:"Some initial option"}; $("#select2").select2({ placeholder: "Select Option", minimumInputLength: 2, ajax: { url: "/servletToGetMyData", dataType: 'json', data: function (term, page) { return { term: term }; }, results: function (data, page) { return { results: data.results} } }, initSelection : function(element, callback){ callback(initialSelection); }, escapeMarkup: function (m) { return m; } }); The AJAX links to

Get Selected value from Multi-Value Select Boxes by jquery-select2?

北城余情 提交于 2019-11-27 11:39:17
I am using Select2 Jquery to bind my dropdown which is used for multiple selection . I am using select2 jquery. It's working fine, I can bind my dropdown but I need to get the selected value from my multi-value selector. I am looking for method to get value which is supported by select2 Jquery. it might be having a function get selected value. my drop down binding code $(".leaderMultiSelctdropdown").select2( { maximumSelectionSize: 4 }); alert("Selected value is: "+$(".leaderMultiSelctdropdown").select2("val")); alternatively, if you used a regular selectbox as base, you should be able to use

JQuery Select2 - How to select all options

纵饮孤独 提交于 2019-11-27 11:34:45
I'm using jQuery select2 multi select dropdown. I need to select all options in a dropdown from code. Basically there is a Select All checkbox on which this functionality has to be implemented, I want to select/deselect options from this checkbox. There is a description in thread on github. Quoting ( https://github.com/ivaynberg/select2/issues/195#issuecomment-13489140 by MortadaAK ) which allows you to select everything on ctrl+a $(document).on("keypress",".select2-input",function(event){ if (event.ctrlKey || event.metaKey) { var id =$(this).parents("div[class*='select2-container']").attr("id

select2 changing items dynamically

痞子三分冷 提交于 2019-11-27 11:00:40
I have two selects that are linked: Each value of the first select determines which items will be displayed in the second select. The values of the second select are stored in a two-dimension array: [ [{"id":1,"text":"a"}, {"id":2,"text":"b"},...], [{"id":"1a","text":"aa"},{"id":"1b","text":"ba"},...], ... ] The first select value determines the index to be used to populate the second select. So in a 'change' event on the first I should be able to modify the items select-two contains. Reading documentation I think I need to use the "data" option... but not shure how as the example loads the

How to get Selected Text from select2 when using <input>

允我心安 提交于 2019-11-27 10:14:14
问题 I am using the select2 control, loading data via ajax. This requires the use of the <input type=hidden..> tag. Now, I want to retrieve the selected text. (The value property in the data-bind expression sotres the id only) I have tried $(".select2-chosen").text() , but this breaks when I have multiple select2 controls on the page. 回答1: As of Select2 4.x, it always returns an array, even for non-multi select lists. var data = $('your-original-element').select2('data') alert(data[0].text); alert

Select2 4.0 - Push new entry after creation

大城市里の小女人 提交于 2019-11-27 09:07:39
I have been using Select2 4.0.0-rc.1 for a couple of weeks (using the ajax adapter) and I am trying to find a way to "push" data after it has been initialized. Within the dropdown list, I have the choice to select an entry in the list (using ajax ) add a free entry (using createTag ) add a new entry If I select "add a new entry", I can fill out a form, and once saved, the new data must be shown as a selected entry. If I push data using select2_existing.select2( { data: data } ).val( 4 ); it works, but ajax call does not work anymore. I have then to destroy select2 re-create it Which will then

Cloned Select2 is not responding

无人久伴 提交于 2019-11-27 07:25:23
I am trying to clone a row which contains select2 tool ,when i clone that row using jQuery the cloned select2 is not responding.In image given below first select2 which is original is working fine but 2nd and 3rd select2 which are cloned not responding code snippet: $(document).ready(function() { var clonedRow = $('.parentRow').clone().html(); var appendRow = '<tr class = "parentRow">' + clonedRow + '</tr>'; $('#addRow').click(function() { $('#test').after(appendRow); }); }); <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <tr class="parentRow" id="test

How to set selected value of jquery select2?

旧巷老猫 提交于 2019-11-27 07:02:15
This belong to codes prior to select2 version 4 I have a simple code of select2 that get data from ajax $("#programid").select2({ placeholder: "Select a Program", allowClear: true, minimumInputLength: 3, ajax: { url: "ajax.php", dataType: 'json', quietMillis: 200, data: function (term, page) { return { term: term, //search term flag: 'selectprogram', page: page // page number }; }, results: function (data) { return {results: data}; } }, dropdownCssClass: "bigdrop", escapeMarkup: function (m) { return m; } }); This code is working, however, I need to set a value on it as if in edit mode. When

How to Set Selected value in Multi-Value Select in Jquery-Select2.?

╄→гoц情女王★ 提交于 2019-11-27 06:52:36
hi all i am binding my dropdown with Jquery-Select2. Its working fine but now i need to Bind my Multi-Value selectBox by using Jquery-Select2. My DropDwon <div class="divright"> <select id="drp_Books_Ill_Illustrations" class="leaderMultiSelctdropdown Books_Illustrations" name="drp_Books_Ill_Illustrations" multiple=""> <option value=" ">No illustrations</option> <option value="a">Illustrations</option> <option value="b">Maps</option> <option value="c">Portraits</option> </select> </div> From this link http://ivaynberg.github.com/select2/ i am using Mutiple Value Select Box , I can Bind my