jquery-select2

Select2, when no option matches, “other” should appear

落爺英雄遲暮 提交于 2019-12-22 05:14:27
问题 With select2 dropdown, how do I get a default option to appear if no options match the user's typed input? $("something").select2({ formatNoMatches: function(term) { //return a search choice } }); I haven't been able to find anything that really matches this desired functionality within the select2 documentation or Stack Overflow. Edit I'm getting closer with this $("something").select2({ formatNoMatches: function(term) { return "<div class='select2-result-label'><span class='select2-match'><

jQuery Select2 Tag on Blur

梦想的初衷 提交于 2019-12-22 04:06:19
问题 I'm using Select2 to create a Gmail-style e-mail addresses field in my application. It works great except for one case: when the user types in an e-mail address and doesn't put a space or comma after it, and doesn't hit enter or tab. For example, if they just type an e-mail address and then use the mouse to select the next field in the form, the e-mail address they typed goes away. I have an example jsfiddle here that illustrates the problem. Here's how I'm setting up select2 on my hidden

How to break a line in select2 dropdown?

浪子不回头ぞ 提交于 2019-12-22 02:03:43
问题 I am using a select 2 dropdown and then showing some long sentences in its content. I want to add line breaks to the sentence at the right place but the drop down is auto adjusting. For example the content of the dropdown right now looks like this : The line looks like this right now select 2 installments of $100. (special offer.) I Need to add controlled line breaks so that it looks like this: select 2 installments of $100. (special offer.) I don't wan't to increase the width of dropdown or

How does a select2 widget gets populated with AJAX?

China☆狼群 提交于 2019-12-21 22:33:03
问题 When I enter a few characters in my widget, I get results like these from AJAX: [{"id":550,"campName":"IB Resi Showtime Rebate Website"},{"id":60,"campName":"OB ACGBK EB"}] However, I'm missing the part on how to populate the widget with those results. Here is the code I use for the widget: $this->widget ( 'ext.ESelect2-master.ESelect2', [ 'selector'=>'#campaigns', 'options'=> [ 'tags'=>$tags, 'allowClear'=>true, 'minimumInputLength' => 2, 'width'=>'300px', 'multiple'=>true, 'placeholder'=>

Knockout.js binding with multiple Select2

人走茶凉 提交于 2019-12-21 12:18:31
问题 My Question is when ever I bind my Select2 with Multiple with Knockout View Model. After selecting one of the options, the data is lost for the second time KnockOutCode $(window).load(function () { ko.bindingHandlers.select2 = { init: function (element, valueAccessor, allBindingsAccessor) { var obj = valueAccessor(), allBindings = allBindingsAccessor(), lookupKey = allBindings.lookupKey; $(element).select2(obj); if (lookupKey) { var value = ko.utils.unwrapObservable(allBindings.value); $

Hiding select2 options

感情迁移 提交于 2019-12-21 12:09:17
问题 I'm trying to hide some of the select2 options, but when I do something like this: <option style="display: none;">...</option> select2 ignores it, unlike when I disable an option, or make it "readonly". Any ideas? 回答1: I stumbled upon this subject when looking for an answer to the same problem and i resolved it using the 'templateResult' callback of select2. <select id="mySelect"> <option value="1" data-show="1">1</option> <option value="2">2</option> <!-- option i want to hide --> </select>

How to pre-select values in select2 multi select?

北城余情 提交于 2019-12-21 07:28:13
问题 I am having a multiple select like this: <select multiple="multiple" class="myList"> <option value="1" selected="selected">Apple</option> <option value="2" selected="selected">Mango</option> <option value="3" selected="selected">Orange</option> </select> Now, apart from those options which must come selected in the select box, I wanted additional ajax functionality which would give values from a remote source. Here is my code for select2 $(function(){ $(".myList").each(function(){ $(this)

How to create autocomplete form with MaterializeCss?

跟風遠走 提交于 2019-12-21 07:18:22
问题 I am looking for autocomplete form for MaterializeCss, any plugins for this? i has try to use select2 but that's css not looks good 回答1: Materialize is an awesome library, I was able to get it to work. $('document').ready(function() { var input_selector = 'input[type=text], input[type=password], input[type=email], input[type=url], input[type=tel], input[type=number], input[type=search], textarea'; /************************** * Auto complete plugin * *************************/ $(input_selector

Auto tokenize last item in pasted string using select2

孤者浪人 提交于 2019-12-21 05:13:30
问题 I am using jQuery Select2 to create an input that allows auto tokenization. I've initialized the select2 input with the following options: { tags: [''], tokenSeparators = [',', ' '] } Very basic stuff. When I type a string of text into the input, followed by a comma or space, the preceding string is tokenized, exactly as I would expect. However, I need to support pasting of text into the input. This is where things fall apart. If I paste '1,2,3,4' into the input, I get separate tokens for 1,

Select2 Dropdown Dynamically Add, Remove and Refresh Items from

社会主义新天地 提交于 2019-12-20 18:29:43
问题 This drives me crazy! Why cant Select2 implement clear methods or examples on their page how to do simple CRUD manipulation on Select2 :) i have a select2 which gets data from a ajax call. <input id="valueg" type="hidden" style="width: 300px;" data-placeholder="Select a Conference" /> $("#valueg").select2({ data: conferences, allowClear: true, initSelection: function (element, callback) { var data = { id: element.val(), text: element.val() }; callback(data); } }).on("change", function (e) { /