jquery-select2-4

Select2: how to add a link instead of “No results found” text?

℡╲_俬逩灬. 提交于 2019-12-24 17:06:27
问题 Following is my code: $('#cow_id_2').select2({ allowClear: true, placeholder: "Search a cow/dam ID", formatNoMatches: function (term) { return "<a href=/'http://google.com/'>Add</a>"; } }); When I try to add a link the plugin just stop working. I am using Select2 4.0.3 version 回答1: If you're using version 4 or newer of select2, try this: $('#cow_id_2').select2({ allowClear: true, escapeMarkup: function (markup) { return markup; }, placeholder: "Search a cow/dam ID", language: { noResults:

Select2: how to add a link instead of “No results found” text?

感情迁移 提交于 2019-12-24 17:03:32
问题 Following is my code: $('#cow_id_2').select2({ allowClear: true, placeholder: "Search a cow/dam ID", formatNoMatches: function (term) { return "<a href=/'http://google.com/'>Add</a>"; } }); When I try to add a link the plugin just stop working. I am using Select2 4.0.3 version 回答1: If you're using version 4 or newer of select2, try this: $('#cow_id_2').select2({ allowClear: true, escapeMarkup: function (markup) { return markup; }, placeholder: "Search a cow/dam ID", language: { noResults:

How to create new tags with Select2 AND save to database

大憨熊 提交于 2019-12-24 02:15:43
问题 So, I'm having a real hard time with Select2. I want users to be able to search through a select list and also create new tags when no search result is found. Creating new tags is not the problem. The main thing - and surprisingly overlooked in most forums - is to INSERT the news tags to the Database. I'm new to Select2, so I'd like to have a full example. And I'm using PHP on this project, so, if there is a way to do this with PHP it would be really helpful. Here is my code: $('

Styling individual select2 tags

浪子不回头ぞ 提交于 2019-12-23 03:53:16
问题 I'm trying to style individual select2 tags using Bootstrap's button styles ( .btn-primary and .btn-danger ) based on if the user created a tag (applying the red .btn-danger style) or if the user selected a existing tag (applying the blue .btn-primary style. I've tried to apply the style during the select event (select2:select) event: $("#ticker_select").on('select2:select', function(e) { // If the e.params.data.id equals e.params.data.txt, // then it is a user-created tag! if (e.params.data

jquery-select2 ajax search display tags in another div

耗尽温柔 提交于 2019-12-20 05:33:09
问题 I would like to display the selected results in another div and not in the input box. function formatRepo (repo) { if (repo.loading) return repo.text; var markup = "<div class='select2-result-repository clearfix'>" + "<div class='select2-result-repository__avatar'></div>" + "<div class='select2-result-repository__meta'>" + "<div class='select2-result-repository__title'>" + repo.full_name + "</div>"; if (repo.description) { markup += "<div class='select2-result-repository__description'>" +

select2 search - match only words that start with search term

纵饮孤独 提交于 2019-12-19 05:23:54
问题 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

How to disable creating new tags with select2 v4.0?

孤街醉人 提交于 2019-12-18 14:02:24
问题 I've been trying out the new Select2 v4.0 which has a lot of improvements. I'm mainly interested in the tags feature. I want to be able to search for tags via ajax and only be able to select a tag from the shown results and not be able to create new tags. The functionality is similar to StackOverflow - if you don't have the necessary reputation you can't create new tags, but you can still tag a question with existing tags. Here's a jsfiddle with my code which is taken from the examples. In

select2 multiple versions on same page/site

≡放荡痞女 提交于 2019-12-18 07:16:32
问题 Afternoon, On a website I already updated lots of elements that used select2 v. 3.5.2 to the new v. 4.0 (and some of those elements are on the header of the website that is present on ALL pages) Unfortunately on some pages of the website the X-editable jquery plugin is used, and that plugin doesn't play well with v 4.0 of select2 (please read: does not play at all) My question is: Can I use both versions of select2 on some pages? And if so, how? Since $(...).select2(); is blind to which

select2 load data using ajax cannot select any option

余生颓废 提交于 2019-12-18 03:10:08
问题 I have the following code (javascript): $('#cbxConnections').select2({ minimumInputLength: 0, multiple: false, allowClear: true, placeholder:{ text:"@Diccionario.Connections", id:" @Diccionario.Connections" }, ajax:{ url:'@Url.Action("GetActiveConnections","Admin")', dataType: 'json', type:'post', data:function(params){ return { q: params.term }; }, processResults: function(data,page){ return { results: data }; } }, escapeMarkup: function (markup) { return markup; }, templateResult: function

Select2 4.0.0 initial value with Ajax

空扰寡人 提交于 2019-12-17 02:54:35
问题 I have a select2 v4.0.0 being populated from an Ajax array. If I set the val of the select2 I can see via javascript debugging that it has selected the correct item (#3 in my case), however this is not shown in the select box, it is still showing the placeholder. Whereas I should be seeing something like this: In my form fields: <input name="creditor_id" type="hidden" value="3"> <div class="form-group minimal form-gap-after"> <span class="col-xs-3 control-label minimal"> <label for="Creditor: