jquery-select2

select2 validation - Select a minimum of one value

非 Y 不嫁゛ 提交于 2020-01-04 17:17:41
问题 I am using select2 and jQuery Validation plugins. HTML for select2: <div class="form-group"> <label for="select2Region"><h3>Set Location</h3></label><br /> <input type="hidden" id="select2Region" style="width:40%" required/> </div> select2 Initiation: $('#select2Region').select2({ minimumInputLength: 1, data: $.parseJSON(selectRegion), placeholder: "Enter your City here", allowClear: true }); Data is populating perfectly fine. Now, i want users to select a value. As is mentioned in Github, i

select2 validation - Select a minimum of one value

南楼画角 提交于 2020-01-04 17:17:10
问题 I am using select2 and jQuery Validation plugins. HTML for select2: <div class="form-group"> <label for="select2Region"><h3>Set Location</h3></label><br /> <input type="hidden" id="select2Region" style="width:40%" required/> </div> select2 Initiation: $('#select2Region').select2({ minimumInputLength: 1, data: $.parseJSON(selectRegion), placeholder: "Enter your City here", allowClear: true }); Data is populating perfectly fine. Now, i want users to select a value. As is mentioned in Github, i

How to disable options in select2

南笙酒味 提交于 2020-01-04 06:19:43
问题 I want to take user's preference with select2. Upon selecting one option the option in other select2 should disable. Sample: Preference 1: Option 1 Option 2 Option 3 Option 4 Preference 2: Option 1 Option 2 Option 3 Option 4 Preference 3: Option 1 Option 2 Option 3 Option 4 Preference 4: Option 1 Option 2 Option 3 Option 4 If I select option 1 in preference 1 it should disable in preferences 1,2,3,4 and if I select option 2 in preference 2 it should disable in preferences 1,2,3,4 and if I

select2 display not updating label text but value is changing

北战南征 提交于 2020-01-04 06:15:13
问题 I am using select2 v4.0.3 along with JQuery. I initialize my selectors as: $("#datatype").select2({ theme: "classic" }); $("#unit").select2({ theme: "classic" }); Then I want to detect a change on #datatype and change the value of #unit which I do as follows: $("#datatype").on('select2:select',function () { $("#unit").val('21'); //udpate unit type to be 'none' }); The problem is that the value of #unit is getting set to 21 but the displayed label for that selector is not updating. Any

Select2 cancel/preventDefault select2:select at specific condition (v.4.0.x)

≡放荡痞女 提交于 2020-01-04 05:41:10
问题 I need to add a Button to every select2 item and prevent the default event so only the button gets triggered. I have the following code but the normal onSelect event still gets triggered: select.on('select2:select', test2); function test2(e) { if (e.params.originalEvent.target.classList.contains('TreeButton')) { //stop event execution e.stopPropagation(); e.preventDefault(); return false; } else { //execute normal } } 回答1: Try to catch select2:selecting event: select.on("select2:selecting",

Select2 ajax not showing results

孤街醉人 提交于 2020-01-03 18:37:06
问题 I am using select2 and ajax to query my database for terms under a certain taxonomy, but when I search the search boxes just hangs on "searching" without retrieving any results. This is my html <select multiple="" name="regions1[]" id="regions1" class="job-manager-multiselect select2-hidden-accessible" required="" tabindex="-1" aria-hidden="true"></select> My jquery: <script> jQuery(function($) { $(document).ready(function() { $( "#regions1" ).select2({ ajax: { url: "/ajax/connect.php",

Dependent Dropdown Contents with jquery-select2

限于喜欢 提交于 2020-01-03 17:06:33
问题 I have a Rails 4 app where I'm using Jquery-select2 for my dropdown lists. I have two dropdowns where I want the selection in the first do dictate what the user can select in the second. Sort of like selecting a country and being given a list of states for that country. In my application I have Demographic and Response models. When someone selects a Demographic I want to populate the Responses list with the appropriate items for that Demographic. I had this working before I started using

Select2 - How to insert a bolded headline?

允我心安 提交于 2020-01-03 17:00:01
问题 I've looked in all the select2's documentation and could not find how can I insert those bold headlines: Can someone provide a complete code example (CSS needed ?) of how to achieve this? 回答1: The example takes one drop down and runs select2 on each, if you are trying to get the example page working HTML should look exactly like this <select style="width:300px" id="source"> <optgroup label="Alaskan/Hawaiian Time Zone"> <option value="AK">Alaska</option> <option value="HI">Hawaii</option> <

Populate Select2 with AJAX data

Deadly 提交于 2020-01-03 13:33:19
问题 I'm using Select2 4.0.0-rc.2. The Options page states the following about initSelection In the past, Select2 required an option called initSelection that was defined whenever a custom data source was being used, allowing for the initial selection for the component to be determined. This has been replaced by the current method on the data adapter. I only found examples for older versions of Select2 that use initSelection (see Setting initial values on load with Select2 with Ajax) How can I

How to use select2 with Meteor?

时光毁灭记忆、已成空白 提交于 2020-01-03 13:02:49
问题 can someone explain to me how select2 works with Meteor? I am using zimme:select2-boostrap3-css and I have no clue on how to use it. I checked both the original select2 github page and the one from the package. The first one explains how to use it without Meteor. Do I just add the jQuery code to one of my *.js-files in order to get it to work? In HTML: <select class="input" id="clientName" name="clientName"> {{#each getClients}} <option value="{{clientName}}" data-id={{_id}}>{{clientName}}<