Hot answers tagged

6

Ok, I found the way. It's just passing an array of option values to 'val' argument: $('#my_select2').select2('val', ["value1", "value2", "value3"]);


5

Try below code: CRM.$(function($) { $('#billing_country_id-5').change(function () { var countryId = $(this).val(); }); }); HTH Pradeep


5

Figured this out. I needed to wrap my jQuery code in: CRM.$(function($) { }); The change trigger - and other select2 events - started working once I did this.


5

Solution is to either patch the ../web/libraries/civicrm/bower_components/select2/select2.js and select2.min.js files or WARNING: select2 4.0.12 is not compatible with CiviCRM 5.21. The admin toolbar will disappear if you do the following. Use the patches. Do not bower install select2! ;-): Move the select2 folder out of bower_components and run: $ ...


2

The cause was that I had the "Select2" Drupal module installed, which was adding a second Select2 widget to my search actions, breaking them. To resolve: Go to Drupal Configuration menu » User Interface » Select2. Click the Exclusion Rules tab. Under Don't load Select2 for specific pages, enter civicrm/* and save your changes. This should fix your ...


2

In general, when you want to listen to an event on a select2 you place the listener on the original form element (which is either an <input> or a <select>). When inspecting the dom, you'll see it close to the select2 div, hidden because it has the select2-offscreen class.


2

The width for Select2 fields is set as an inline style to the element itself. So, to override the inline width, you'd have to use !important in your CSS. For reference: https://stackoverflow.com/q/16813220


1

According to this related question, it should be possible to do this via: $('#id-of-select2').select2('val', 'value-to-select'); or, if you want to select multiple items in a multiselect: $('#id-of-select2').select2('val', ['value-to-select', 'another-value']);


1

For some reason, you can't use the ngOptions directive with select2 multi-select elements. You need to manually specify the <option> elements with ngRepeat like this instead: <select crm-ui-select="{allowClear: true}" ng-model="myVar" multiple="multiple" class="big" > <option ng-repeat="option in options" value="{{option.value}}"&...


1

you can also do it this way by defining javascript array. var Values = new Array(); Values.push("value1"); Values.push("value2"); Values.push("value3"); $("#my_select2").val(Values).trigger('change');


1

I recently figured out that you can add a style parameter when generating the Select2. For instance, I was able to force a 600px width here: $form->addEntityRef("financial_account[$i]", ts('Source Fund'), [ 'entity' => 'financial_account', 'style' => 'width: 600px;', 'api' => [ 'params' => [ '...


Only top voted, non community-wiki answers of a minimum length are eligible