jquery-select2

jQuery select2 get value of select tag?

拈花ヽ惹草 提交于 2019-12-28 08:07:17
问题 Hello friends this is my code: <select id='first'> <option value='1'> First </option> <option value='2'> Second </option> <option value='3'> Three </option> </select> This is my select2 code: $("#first").select2(); Below is code for getting selected value. $("#first").select2('val'); // It returns first,second,three. This is return a text like first,second,three and I want to get 1,2,3 . Means I need the value of select box, not text. 回答1: $("#first").val(); // this will give you value of

Dynamically add item to jQuery Select2 control that uses AJAX

半腔热情 提交于 2019-12-28 02:42:26
问题 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,

Dynamically add item to jQuery Select2 control that uses AJAX

我怕爱的太早我们不能终老 提交于 2019-12-28 02:42:11
问题 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,

Select2 dropdown but allow new values by user?

情到浓时终转凉″ 提交于 2019-12-27 12:37:32
问题 I want to have a dropdown with a set of values but also allow the user to "select" a new value not listed there. I see that select2 support this if you are using it in tokens mode, but is there a way to do it without having tokens? 回答1: For version 4+ check this answer below by Kevin Brown In Select2 3.5.2 and below, you can use something like: $(selector).select2({ minimumInputLength:1, "ajax": { data:function (term, page) { return { term:term, page:page }; }, dataType:"json", quietMillis

selec2 search - Return no results found message if a specific criteria didnt match

蹲街弑〆低调 提交于 2019-12-25 16:43:44
问题 I am using select2 4.0.3 for search drop down. As per my understanding its default functionality is not to match with the start of entries the drop down have. So I have implemented the below given code function matchStart(params, data) { params.term = params.term || ''; if (data.text.toUpperCase().indexOf(params.term.toUpperCase()) == 0) { return data; } return false; } $("select").select2({ placeholder : "Input country name or select region", matcher : function (params, data) { return

selec2 search - Return no results found message if a specific criteria didnt match

橙三吉。 提交于 2019-12-25 16:43:02
问题 I am using select2 4.0.3 for search drop down. As per my understanding its default functionality is not to match with the start of entries the drop down have. So I have implemented the below given code function matchStart(params, data) { params.term = params.term || ''; if (data.text.toUpperCase().indexOf(params.term.toUpperCase()) == 0) { return data; } return false; } $("select").select2({ placeholder : "Input country name or select region", matcher : function (params, data) { return

xeditable & select2 dropdown w/ajax source displaying empty after submitting

≯℡__Kan透↙ 提交于 2019-12-25 11:56:12
问题 I've gotten xeditable and select2 to work with an api call as the source and everything works great EXCEPT the following. After submitting the select2 dropdown, the value of the table is displayed as EMPTY and requires a page refresh in order to update to the correct value. Does anyone know how to update the value to the selected select2 dropdown value? my html: <td class="eo_role"><a href="#" data-pk={{r.pk}} data-type="select2" data-url="/api/entry/{{r.pk}}/" data-name="eo_role" data-title=

preselect Item in select2

﹥>﹥吖頭↗ 提交于 2019-12-25 08:08:04
问题 I am using Select2 inside my Asp.net MVC project. I created a weblog. each post has some tags. I am using select2 multiselect to choose tags. In the create page i can search and select tags and save in database. problem: in edit page also my select2 works fine. but I want to add some tags in edit pageload which the user added in create page. then user can change tags. I can not preselect tags in select2 回答1: This little jquery function will add options to a select2 $.fn.select2AddOptions =

jquery select2 tags bugs in safari

与世无争的帅哥 提交于 2019-12-25 07:59:50
问题 Everything works fine on desktop resized to mobile dimensions. It is a Ruby on Rails app. Bug #1 I don't know how to describe this but when I am entering letters into the input (that select2 is called on) on my iphone in Safari, it shakes/jolts/moves up and down after each letter is entered. Bug 2 After tags have been entered and you press "done" on the Iphone keyboard, the select2-dropdown will sometimes remain open. It is very finicky. Script: $(document).on('page:change', function () { $('

select2 is not a function, wordpress

被刻印的时光 ゝ 提交于 2019-12-25 04:28:13
问题 I'm a beginner in wordpress,recently I installed the dokan plugin for my online shop, gave me problems and I read that the solution was add this code add_action('wp_enqueue_scripts', 'mgt_dequeue_stylesandscripts',99); function mgt_dequeue_stylesandscripts() { if ( class_exists( 'woocommerce' ) ) { wp_dequeue_style( 'select2' ); wp_deregister_style( 'select2' ); wp_dequeue_script( 'select2'); wp_deregister_script('select2'); } } I am using the handy store template, so I put the code in the