select2

How can I show more than one white space character in a row in a select2 data row?

假如想象 提交于 2019-12-12 02:42:13
问题 I'm using Select2 and I use the {data: [{id:1, text: "..."}] approach to define the options. I want to format each option by grouping the substring it's made up of using more than one white space character. So something like this: {data: [ {id:1, text: "Trees - Oak"}, {id:2, text: "Trees - Pine"}, {id:3, text: "Seas - North Sea"}, {id:4, text: "Seas - Baltic Sea"} ]} When I do this they show up as one space in the resulting dropdown (the default HTML way of dealing with spaces). When I use  

How to update select2 drop down in codeigniter

痴心易碎 提交于 2019-12-11 12:17:18
问题 Hi i am using select2 jquery plugin to insert multiple values to a drop down but when i am trying to update i am facing problem can anyone help me out in showing the right way of doing this <?php $cats = explode(',',$r['keyword_whomtoteach']); foreach($cats as $vald) { foreach($keyword as $key=>$keywords) { if ($vald == $keywords->keyword_id) { ?> <option value="<?php echo $keywords->keyword_id; ?>" <?php { echo "selected"; } ?>><?php echo $keywords->keyword_name; ?></option> <?php } else { ?

How to execute select2() function on dynamically created select list?

人盡茶涼 提交于 2019-12-10 20:54:22
问题 I am simply creating a select list dynamically on a button click and appending it to a div. It is working without a problem but when I want this select list to behave like searchable as expected for select2 it is not working. In below, I'm passing my select list into a method with an html helper named GGroupDropDownListForJavascript and the html result is like below. <select class="form-control input-xxlarge select2me" id="TagCategoryId" name="TagCategoryId"> <option value="cf1d7da6-f49f-47aa

select2全选所有的选项

烂漫一生 提交于 2019-12-10 15:40:02
要实现select2全选所有的选项,上网搜了一圈,居然没发现答案,自己写了个方法。 传入select2的Id即可。 //select2全选所有的选项 function chooseSelect2All(select_id) { //document的对象,可以取到option var item = document.getElementById(select_id)//$('#'+select_id); //jquery的对象,用来指定select2控件的选择项 var item_jq = $('#'+select_id); var option_list = []; for(var i=0; i< item.length;i++){ var optionVal = item[i].getAttribute('value'); option_list.push(optionVal); } item_jq.val(option_list).trigger("change"); } 说明一下: document.getElementById获取的是html的对象, 可以用下标获取到所有option的值,放在列表中。 然后在用$('#id')的方式获取jquery对象。 使用.val(option_list).trigger("change");设置选择项。 来源: oschina 链接

How to set select value in select2 plugin - jquery

陌路散爱 提交于 2019-12-10 06:35:24
问题 I use this code for insert data to select element with select2 plugin: $.ajax({ type: "POST", url: "ws.asmx/GetEvrakGrup", data: "{}", contentType: "application/json; charset=utf-8", dataType: "json", success: function (dc, status) { jsonData = JSON.parse(dc.d); $("#selectId").select2({ data: jsonData }); }, error: function () { alert("This is an Error");} }); After I want to set a value in this select but its not working: $("#selectId").val(81); 回答1: Try this : $("#selectId").val(81).trigger

Select2 Multiple: Add several items with one copy+paste

会有一股神秘感。 提交于 2019-12-08 07:44:34
问题 I want to add several items in a select2 input field at once. If I copy+paste "Hawaii Alaska" into the select-multiple example here, then I get: No results found In my case spaces are not allowed in the items. Is there a way to insert N space sperated items via copy+paste? Desired result: (x)Hawaii (x)Alaska 回答1: you can add token separators in your select2 to identify characters as stopping points for your tags/choices, but unfortunately it bugs on the last copy pasted item //try copy

How to set data-* from datasources in Select2?

∥☆過路亽.° 提交于 2019-12-08 06:37:54
问题 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":

how to get the data-* value of a selected option in select2?

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-08 03:33:16
问题 This is like a second part of this topic and right now I need to be able to read dynamic data-* properties from one select to the other. What this mean? First take a look to the following image: What you're seeing there is what the following code does: // This turn 1st and 3rd into select2 $('#module, #conditions').select2(); // This turn 2nd into select2 using data from a datasource $('select#fields').select2({ placeholder: 'Select a field', data: data.fields }); As I posted in the

YII2 Select2插件使用小计

前提是你 提交于 2019-12-07 21:22:11
先给出文档的地址: https://www.yiiframework.com/extension/yii-select2 最近在看到很多网站给用户打标签,或者是多个下拉选择之后变成一个标签。觉得交互不错!调研发现有开源的yii-select2这个插件,记录下使用步骤; 1,composer安装yii-select2插件,执行命令 composer require kartik-v/yii2-widget-select2 "@dev" 即可,之后就会自动加载到项目。 2,笔者这用的YII2框架,所以模板是混写的代码如下: <?php echo $form->field($model, 'id')->widget(Select2::classname(), [ 'data' => $list, 'options' => ['multiple' => true, 'placeholder' => '请选择...'], ])->label('Label Name'); ?> 其中变量$model,为当前controller获取数据model,$list是下拉列表的数组。kv结构。 3,这个插件在添加的时候没有问题;但是在编辑的时候,需要使用js再次填充默认值。JavaScript脚本如下: <script type="text/javascript"> jQuery(document)

How to set data-* from datasources in Select2?

北慕城南 提交于 2019-12-07 02:44:31
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-type": "varchar" }, { "id": "companies_number", "text":