jquery-select2

select2 and jquery validation not working properly

若如初见. 提交于 2019-11-27 16:22:43
Trying to use validation on select2 with a few issues : the error message will show, but it will not remove when a valid entry is entered. I am loading an initial value which works fine... the validator, however, does not recognize the value and tells me it is invalid... I have to manually type in the same value and then it validates, but still does not remove the error class/message showing it is valid. form : <div class="col-md-12 margin-bottom-30 form-group"> <div class="input-modal-group"> <label for="vedit-filter" class="f-14"><b>filter :</b></label> <input id="vedit-filter" type="text"

How to test a Select2 element with capybara DSL?

元气小坏坏 提交于 2019-11-27 15:50:03
问题 I have a Select2 element on a page that loads results via ajax. Would like to test this with capybara/rspec (using the poltergeist driver), but since the Select2 element actually starts out as a hidden field, and then populates a <ul> once results are processed, none of the normal select , fill_in or choose helpers will work. What I have now is something like it "should have a search field for events" do click_link "Select an Event" # this works as expected within('.select2-container') do #

Get custom data-attribute in select2 with <select>

血红的双手。 提交于 2019-11-27 15:47:25
问题 Let's assume you have the following HTML5 <select id="example"> <option value="AA" data-id="143">AA</option> <option value="BB" data-id="344">BB</option> </select> $("#example").select2(); How do I get the data-id from the selected option ? 回答1: There is no direct method with select2, you can use a combinaison of select2 data and jQuery : $("#example").select2().find(":selected").data("id"); First you get the select2 data then you find your selected option with jQuery and finally the data

How to programmatically inject search queries into Select2 v4?

人盡茶涼 提交于 2019-11-27 15:43:19
问题 I've built a web-app using a Select2 search box, which connects to our backend via AJAX. The search box passes the query (say "APPLES") to the backend, which then updates the page. How do I programmatically inject search queries into the search box? I need to pass in the "val" so that select2 calls the backend via AJAX and updates the page. I'm sure this is obvious, but I couldn't find it in the documentation. For example, instead of forcing a user to type "APPLES" into the search box, I

How to enable infinite scrolling in select2 4.0 without ajax

坚强是说给别人听的谎言 提交于 2019-11-27 15:16:22
问题 I am using select2 with custom data adapter. All of the data provided to select2 is generated locally in web page (so no need to use ajax). As query method can generate a lot of results (about 5k) opening select box is quite slow. As a remedy, I wanted to use infinite scroll. Documentation for custom data adapter says that query method should receive page parameter together with term : @param params.page The specific page that should be loaded. This is typically provided when working with

Select2 with createSearchChoice uses newly created choice for keyboard entry even given a match, bug or am I missing something?

你离开我真会死。 提交于 2019-11-27 14:54:41
问题 I'm using Select2 (version 3.4.0) to populate a tag list. The tags are matched against existing ones via ajax call, and I'm using createSearchChoice to allow creating new tags. The code works so far, and looks something like this: $(mytags).select2({ multiple: true, placeholder: "Please enter tags", tokenSeparators: [ "," ], ajax: { multiple: true, url: myurl, dataType: "json", data: function(term, page) { return { q: term }; }, results: function(data, page) { return data; } },

How can I using select2 with webpack?

强颜欢笑 提交于 2019-11-27 13:49:40
问题 I'm using webpack to manage all my assets, when I use this code to require select2 (https://github.com/select2/select2) I got the error $(...).select2 is not function. require.ensure(['./vendors/select2'],function (require) { require('./site'); }); // site.js (function ($) { $(document).ready(function () { $(".js-1example-basic-single").select2(); }); })(jQuery); I think there is something wrong with module export. I tried many search but no hope. Anyone please tell me what to do, It took me

Setting initial values on load with Select2 with Ajax

拥有回忆 提交于 2019-11-27 13:30:30
问题 I have select2 controls set up with Ajax (have both single and multiple). I'm trying to have some values on page load but I'm not able to get this to work however. My code for select2 is given below: function AjaxCombo(element, url, multival ){ // multival = true or false multival = multival || false; $(element).select2({ minimumInputLength: 2, multiple: multival, separator: '|', ajax: { url: url, dataType: 'json', data: function (term, page) { var targetname = $(this).attr('name'); var

How to use placeholder as default value in select2 framework

时光总嘲笑我的痴心妄想 提交于 2019-11-27 13:26:22
To get the chosen value of a select2 I'm using: var x = $("#select").select2('data'); var select_choice = x.text The problem is this throws an error if not value has been selected and I was wondering if there was any way to make it return the placeholder if no option is selected meherzi.sahbi You have to add an empty option (i.e. <option></option> ) as a first element to see a placeholder. From Select2 official documentation : "Note that because browsers assume the first option element is selected in non-multi-value select boxes an empty first option element must be provided ( <option></option

select2 force focus on page load

这一生的挚爱 提交于 2019-11-27 13:24:48
问题 I am trying to make a select2 box appear in its focused state on page load. I have tried the following: $('#id').select2('focus'); $('#id').trigger('click'); $('#id').trigger('focus'); Only the first line seems to have any effect, and it does focus the select2 field, however it requires an additional keypress to display the search field, and to allow typing in search string. Therefore, if you load the page and start typing: "Search", the "S" will open the search box and then the remainder of