jquery-select2

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

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

How to set Default Value in tagging in select2 jquery

我只是一个虾纸丫 提交于 2019-12-01 04:08:19
问题 I am using select2 (http://ivaynberg.github.io/select2/) for my tagging input. from the example in using select2 tagging the code is look like this. $("#e12").select2({tags:["red", "green", "blue"]}); now my problem is how can I insert default value in my input just like in the page example in http://ivaynberg.github.io/select2/ at Tagging Support, the input has a default value of 'brown', 'red', & 'green'. 回答1: You can initialize the Select2 control by providing a value for the hidden input:

Passing Custom Headers to Ajax request on Select2

此生再无相见时 提交于 2019-12-01 03:28:00
We are trying to implement Ajax Remote data loading in Select2:- $scope.configPartSelect2 = { minimumInputLength: 3, ajax: { url: "/api/Part", // beforeSend: function (xhr) { xhr.setRequestHeader('Authorization-Token', http.defaults.headers.common['Authorization-Token']); }, // headers: {'Authorization-Token': http.defaults.headers.common['Authorization-Token']}, data: function (term, page) { return {isStockable: true}; }, results: function (data, page) { // parse the results into the format expected by Select2. // since we are using custom formatting functions we do not need to alter remote

Unable to select a result from the select2 search results

北城以北 提交于 2019-12-01 03:07:13
I am using the select2 for on of my search boxes. I'm getting the results from my URL but I'm not able to select an option from it. I want to use the 'product.productName' as the text to be shown after selection. Is there anything that I have missed out or any mistake that I have made. I have included select2.css and select2.min.js,jquery.js function dataFormatResult(product) { var markup = "<table class='product-result'><tr>"; markup += "<td class='product-info'><div class='product-title'>" + product.productName + "</div>"; if (product.manufacturer !== undefined) { markup += "<div class=

select2 search - match only words that start with search term

╄→尐↘猪︶ㄣ 提交于 2019-12-01 03:05:02
I migrated from chosen to select2 plugin because it works better for me, but its documentation is very poor when compared to chosen. Could anyone tell me what option(s) should be used to make select2 search function to filter words that just begin with search term (and don't contain it in the middle). Let's say select2 field has those options: banana, apple, pineapple. When user enters "app" (or apple), only apple should be returned (because it's the only word that starts with apple). Now, it returns both apple and pineapple. After lots of search I figured out that some custom matcher needs to

Prevent reload of data with select2 plugin (v4)

懵懂的女人 提交于 2019-12-01 00:58:51
I'm using select2 plugin(v4) and loading his options with ajax. If i open the select input on the first time the data will be loaded. When I open the select again, the same data is reloaded. There is any way to prevent this "reloading" of data? I mean, if i just open the select2 and the options were previously loaded I don't want to load again. Here is my current code: $(select_input).select2({ ajax: { url: url, dataType: 'json', quietMillis: 250, data: function (params) { return { term: params.term, page: params.page, page_limit: default_page_size }; }, processResults: function (data) {

SELECT2 -> Add data without replacing content

我是研究僧i 提交于 2019-11-30 21:36:35
I've had a look at some other threads but nothing quite as specific. It's not really something that I would assume is hard but I'm not sure how about to do it. Currently I'm using Select2 for a tagging system and next to it I have suggested tags which users would be able to click on and it will add to the box. Instead, each tag is replacing the content and adding itself. I need the adding to be appended into the box without replacing what's already in there. Here's my code: $(document).on('click', ".tag1", function () { var value = $(".tag1").html(); console.log(value); $("#selectPretty").val(

Rails acts-as-taggable-on with select2 (and simple_form)

落花浮王杯 提交于 2019-11-30 21:29:35
I would like to have a select2 dropdown of tags, where i could select multiple existing tags and add new ones. I have tried many different ways and i either don't get select2 box working or only one value is passed (last one). This is closest i got (passes last value): <%= f.input :tag_list, collection: @model.tags.map { |t| t.name }, input_html: { :style=> 'width: 300px', class: "taggable", data: { placeholder: "Tags" }} %> As I mentioned before, normal select2 library now uses only select input types, but it does work with input types when using select2-full library. So, this was a way out

Prevent reload of data with select2 plugin (v4)

最后都变了- 提交于 2019-11-30 19:58:27
问题 I'm using select2 plugin(v4) and loading his options with ajax. If i open the select input on the first time the data will be loaded. When I open the select again, the same data is reloaded. There is any way to prevent this "reloading" of data? I mean, if i just open the select2 and the options were previously loaded I don't want to load again. Here is my current code: $(select_input).select2({ ajax: { url: url, dataType: 'json', quietMillis: 250, data: function (params) { return { term:

Load values in select2 multiselect

陌路散爱 提交于 2019-11-30 19:47:36
I'm using select2 in place of search box. Here i'm using to load countries values like this $("#countries").select2({ multiple: true, tags:["India", "Japan", "Australia","Singapore"], tokenSeparators: [","] }); When i press save button, they are properly submitted to the server, now here the question is when i want to modify the country field after saving to server, how i can load the saved values to the country field. This is how i retrieve data from server $.getJSON('/dataprovider?data=fetchCountriesForm', function(opts) { //the opts here contains the json values of the countries. //what