- $valField.show().val('');
- if (filterSpec.options) {
- CRM.utils.setOptions($valField, filterSpec.options, false, filter.value);
- } else {
- $valField.prop('disabled', true);
- // Fieldname may be prefixed with joins - strip those out
- var fieldName = _.last(filter.key.split('.'));
- CRM.api3(filterSpec.entity || $el.data('api-entity'), 'getoptions', {field: fieldName, context: 'search', sequential: 1})
- .done(function(result) {
- var entity = $el.data('api-entity').toLowerCase(),
- globalFilterSpec = _.find(CRM.config.entityRef.filters[entity], {key: filter.key}) || {};
- // Store options globally so we don't have to look them up again
- globalFilterSpec.options = result.values;
- $valField.prop('disabled', false);
- CRM.utils.setOptions($valField, result.values);
- $valField.val(filter.value || '');
- });
+ $('.crm-entityref-filter-value', '#select2-drop').remove();
+ $valField = $(entityRefFilterValueMarkup(filter, filterSpec));
+ $keyField.after($valField);
+ if (filterSpec.type === 'select' && !filterSpec.options) {
+ loadEntityRefFilterOptions(filter, filterSpec, $valField, $el);