From 8c3a97ed719da8d25aeaa228446c0d679eba509c Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Sun, 18 Oct 2015 22:22:16 -0400 Subject: [PATCH] CRM-16415 - Fix crmSelect2 placeholder icons --- ang/crmUi.js | 2 +- css/civicrm.css | 4 ++++ js/Common.js | 18 ++++++++++-------- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/ang/crmUi.js b/ang/crmUi.js index b5c76b2c3d..d62d44153e 100644 --- a/ang/crmUi.js +++ b/ang/crmUi.js @@ -599,7 +599,7 @@ function init() { // TODO watch select2-options - element.select2(scope.crmUiSelect || {}); + element.crmSelect2(scope.crmUiSelect || {}); if (ngModel) { element.on('change', refreshModel); $timeout(ngModel.$render); diff --git a/css/civicrm.css b/css/civicrm.css index 71e9c1a91c..39eaa364f3 100644 --- a/css/civicrm.css +++ b/css/civicrm.css @@ -3110,6 +3110,10 @@ div.m ul#civicrm-menu, .crm-container .crm-action-menu .select2-default span.select2-chosen { color: #2786C2; } +.crm-container .select2-container[class*=" fa-"]:before { + display: none; +} + /* Restore this property otherwise our css overrides it */ .select2-search input { box-sizing: border-box; diff --git a/js/Common.js b/js/Common.js index e69025c3ad..a812af0c61 100644 --- a/js/Common.js +++ b/js/Common.js @@ -385,10 +385,17 @@ if (!CRM.vars) CRM.vars = {}; // add disabled property for option values $('option[value^=crm_disabled_opt]', this).attr('disabled', 'disabled'); - // Placeholder icon + // Placeholder icon - total hack hikacking the escapeMarkup function but select2 3.5 dosn't have any other callbacks for this :( if ($el.is('[class*=fa-]')) { - iconClass = $el.attr('class').match(/(fa-\S*)/)[1]; - $el.removeClass(iconClass); + settings.escapeMarkup = function (m) { + var out = _.escape(m), + placeholder = settings.placeholder || $el.data('placeholder') || $el.attr('placeholder') || $('option[value=""]', $el).text(); + if (m.length && placeholder === m) { + iconClass = $el.attr('class').match(/(fa-\S*)/)[1]; + out = ' ' + out; + } + return out; + }; } // Defaults for single-selects @@ -403,11 +410,6 @@ if (!CRM.vars) CRM.vars = {}; $el.addClass('crm-ajax-select'); } $el.select2(settings); - if (iconClass) { - window.setTimeout(function() { - $el.select2('container').find('span.select2-chosen').prepend(' '); - }, 10); - } }); }; -- 2.25.1