From 25b621a41dd86aedb88ead3e2dcd57658240a4a6 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Sat, 3 Dec 2022 20:13:45 -0500 Subject: [PATCH] APIv4 Explorer - autocomplete cleanup --- ang/api4Explorer/Explorer.js | 4 ++-- ext/afform/admin/ang/afGuiEditor/afGuiFieldValue.directive.js | 2 +- js/Common.js | 3 +++ 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/ang/api4Explorer/Explorer.js b/ang/api4Explorer/Explorer.js index 817e7103c2..6fb14a55c6 100644 --- a/ang/api4Explorer/Explorer.js +++ b/ang/api4Explorer/Explorer.js @@ -1226,7 +1226,7 @@ $el.crmDatepicker('destroy'); } if ($el.is('.select2-container + input')) { - $el.crmEntityRef('destroy'); + $el.crmAutocomplete('destroy'); } $(element).removeData().removeAttr('type').removeAttr('placeholder').show(); } @@ -1447,7 +1447,7 @@ if (field && suffix) { field.pseudoconstant = suffix; } - // When joining to a 'name' field, value fields should render an appropriate entityRef + // When joining to a 'name' field, value fields should render an appropriate autocomplete if (field && field.type === 'Field' && field.name === 'name' && _.includes(fieldName, '.')) { field.fk_entity = field.entity; field.id_field = 'name'; diff --git a/ext/afform/admin/ang/afGuiEditor/afGuiFieldValue.directive.js b/ext/afform/admin/ang/afGuiEditor/afGuiFieldValue.directive.js index 162a30526f..661eb4b6a3 100644 --- a/ext/afform/admin/ang/afGuiEditor/afGuiFieldValue.directive.js +++ b/ext/afform/admin/ang/afGuiEditor/afGuiFieldValue.directive.js @@ -24,7 +24,7 @@ inputType = field.input_type, dataType = field.data_type; multi = field.serialize || dataType === 'Array'; - $el.crmSelect2('destroy').crmDatepicker('destroy'); + $el.crmAutocomplete('destroy').crmDatepicker('destroy'); // Allow input_type to override dataType if (inputType) { multi = (dataType !== 'Boolean' && diff --git a/js/Common.js b/js/Common.js index dcabd0af5c..7d26948058 100644 --- a/js/Common.js +++ b/js/Common.js @@ -554,6 +554,9 @@ if (!CRM.vars) CRM.vars = {}; // Autocomplete based on APIv4 and Select2. $.fn.crmAutocomplete = function(entityName, apiParams, select2Options) { + if (entityName === 'destroy') { + return $(this).off('.crmEntity').crmSelect2('destroy'); + } select2Options = select2Options || {}; return $(this).each(function() { var $el = $(this).off('.crmEntity'), -- 2.25.1