select2

Capybara select2 helper [closed]

匿名 (未验证) 提交于 2019-12-03 09:14:57
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Maybe it could help someone. Wrote a simple capybara helper to set values into select2 fields. See code below. 回答1: module Features module CapybaraHelpers def select2(value, element_selector) select2_container = first("#{element_selector}") select2_container.find(".select2-choice").click find(:xpath, "//body").find("input.select2-input").set(value) page.execute_script(%|$("input.select2-input:visible").keyup();|) drop_container = ".select2-results" find(:xpath, "//body").find("#{drop_container} li", text: value).click end end end Then in

Disable select2 plugin in JQuery dropdown

匿名 (未验证) 提交于 2019-12-03 09:14:57
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am getting the values from json and displaying it in a popup. I need to disable that option which i am getting from json. How can i do that? I tried normal jQuery but It doesn't work. I tried disabled true that also not working. Please give solution. 回答1: From the select2 docs In case that you need to disable certain options so that they can't be selected by the select2 interface, you can now pass in disabled: true with your data. Please note: This also works for incoming values from ajax. When attached to a element, Select2 will respect

How to set data-* from datasources in Select2?

匿名 (未验证) 提交于 2019-12-03 09:14:57
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am using Select2 as follow: $('select#fields').select2({ placeholder: 'Select a field', data: data.fields }); data.fields is a JSON like this one: "fields": [ { "id": "companies_id", "text": "companies_id", "data-type": "int" }, { "id": "parent_companies_id", "text": "parent_companies_id", "data-type": "int" }, { "id": "client_of_companies_id", "text": "client_of_companies_id", "data-type": "int" }, { "id": "asset_locations_id", "text": "asset_locations_id", "data-type": "int" }, { "id": "companies_name", "text": "companies_name", "data

Using Select2 (multiple selections) with vue.js

匿名 (未验证) 提交于 2019-12-03 09:02:45
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm new to vue and have followed their 'custom directive' at http://vuejs.org/examples/select2.html . This works well when only selecting one item, but when you're selecting multiple items it only passes the first one. I need it to pass all values selected. I have a jsfiddle set up displaying the code which is available here. https://jsfiddle.net/f3kd6f14/1/ The directive is as below; Vue.directive('select', { twoWay: true, priority: 1000, params: ['options'], bind: function() { var self = this $(this.el) .select2({ data: this.params.options

Populate select2 with JSON after init doesnt work

匿名 (未验证) 提交于 2019-12-03 08:44:33
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I'm trying to populate a select2 element with a JSON array; but I can't get it. I have the next array: data = [{"id":"Foo","text":"Foo"},{"id":"Bar","text":"Bar"}] And I initialize select2 as follow: $("#selectElement").select2(); I use the next code to populate: $('#selectElement').select2('data', data, true); But doesnt work and I dont know why. Someone can help me? EDIT: I need to populate after the init of select2 (I receive JSON from AJAX) My intention is populate the select2 of my question with the JSON of the AJAX search of other

How to remove selected option from the option list in select2 multiselect and show selected options in the order they are selected

南楼画角 提交于 2019-12-03 02:34:20
I have select2 multi select field in my form where I want to remove the selected option from the dropdown list after it is selected and again add it to the list if it is removed from the list. And also the added items should be in the same order as they selected. The current select2 (4.0) is not removing the selected the items and and it is showing the selected items in the order they appear in the drop down list, not in the order they are selected. $(document).ready(function(){ $('#dynamicAttributes').select2({ allowClear: true, minimumResultsForSearch: -1, width: 600 }); }); JSFiddle: https:

Select2 4.0.0 Bootstrap theme

匿名 (未验证) 提交于 2019-12-03 02:30:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: In select2 4.0 version there is a theme option. However in the documentation I can't find what does the option mean and how can I create custom theme ( https://select2.github.io/examples.html ) I've found bootstrap 3 theme for select2, but it seems to be working only for 3.5 version. So I could I create custom theme for select2 latest version (4.0)? Basically I need bootstrap 3 styling preferably with LESS file 回答1: @fk is working on a Bootstrap 3 theme for Select2 4.0.0. https://github.com/select2/select2-bootstrap-theme There is not

“query function not defined for Select2 undefined error”

匿名 (未验证) 提交于 2019-12-03 02:28:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Trying to use Select2 and getting this error on multiple item input/text field: "query function not defined for Select2 undefined error" 回答1: Covered in this google group thread The problem was because of the extra div that was being added by the select2. Select2 had added new div with class "select2-container form-select" to wrap the select created. So the next time i loaded the function, the error was being thrown as select2 was being attached to the div element. I changed my selector... Prefix select2 css identifier with specific tag name

Select2.js error: Cannot read property 'length' of undefined

匿名 (未验证) 提交于 2019-12-03 02:26:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am using Select2 jquery plugin and I can't get results with json. When looking json response in browser it looks ok. Like this for example: [{ "id" : "50", "family" : "Portulacaceae " }, { "id" : "76", "family" : "Styracaceae " }, { "id" : "137", "family" : "Dipsacaceae" } ] URL called with ajax in this case is: http://localhost/webpage/json_family.php?term=acac&_=1417999511783 but I can't get that results in select2 input, console says: Uncaught TypeError: Cannot read property 'length' of undefined Here is code: html <input type="hidden"

Add class to select2 element

匿名 (未验证) 提交于 2019-12-03 02:20:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: The documentation is either terrible or I'm missing something. I'm trying to add an error class to a select2 box for form validation. It's just a 1px red border. I found the containerCssClass method in the documentation, but I'm not sure how to apply it. I have tried the following with no luck: $("#myBox").select2().containerCssClass('error'); 回答1: jQuery uses JSON objects to initialize, so I guess this one will as well:\ $("#myBox").select2({ containerCssClass : "error" }); If you want to add/remove a class you can do this after you