// 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 = '<i class="crm-i ' + iconClass + '"></i> ' + out;
+ }
+ return out;
+ };
}
// Defaults for single-selects
$el.addClass('crm-ajax-select');
}
$el.select2(settings);
- if (iconClass) {
- window.setTimeout(function() {
- $el.select2('container').find('span.select2-chosen').prepend('<i class="crm-i ' + iconClass + '"></i> ');
- }, 10);
- }
});
};
selectParams = {};
$el.data('api-entity', entity);
$el.data('select-params', $.extend({}, $el.data('select-params') || {}, options.select));
- $el.data('api-params', $.extend({}, $el.data('api-params') || {}, options.api));
+ $el.data('api-params', $.extend(true, {}, $el.data('api-params') || {}, options.api));
$el.data('create-links', options.create || $el.data('create-links'));
$el.addClass('crm-form-entityref crm-' + entity.toLowerCase() + '-ref');
var settings = {
// Once a filter has been chosen, rerender create links and refocus the search box
$el.select2('close');
$el.select2('open');
+ } else {
+ $('.crm-entityref-links', '#select2-drop').replaceWith(renderEntityRefCreateLinks($el));
}
})
.on('change.crmEntity', 'select.crm-entityref-filter-key', function() {
- var filter = $el.data('user-filter') || {};
- filter.key = $(this).val();
+ var filter = {key: $(this).val()};
$(this).toggleClass('active', !!filter.key);
$el.data('user-filter', filter);
loadEntityRefFilterOptions($el);
});
}
} else {
- $valField.hide();
+ $valField.hide().val('').change();
}
}
$('form[data-warn-changes] :input', e.target).each(function() {
$(this).data('crm-initial-value', $(this).is(':checkbox, :radio') ? $(this).prop('checked') : $(this).val());
});
- $('textarea.crm-form-wysiwyg', e.target)
- .not('.crm-wysiwyg-enabled')
- .addClass('crm-wysiwyg-enabled')
- .each(function() {
- if ($(this).hasClass("collapsed")) {
- CRM.wysiwyg.createCollapsed(this);
- } else {
- CRM.wysiwyg.create(this);
- }
- });
+ $('textarea.crm-form-wysiwyg', e.target).each(function() {
+ if ($(this).hasClass("collapsed")) {
+ CRM.wysiwyg.createCollapsed(this);
+ } else {
+ CRM.wysiwyg.create(this);
+ }
+ });
})
.on('dialogopen', function(e) {
var $el = $(e.target);