From 509e9cf22b65d7262af9f86f562c24e601ff4ce4 Mon Sep 17 00:00:00 2001 From: Georgy Litvinov Date: Thu, 2 Feb 2023 14:24:47 +0100 Subject: [PATCH] Custom forms fixes (#361) * added safety check * Prevent failing autocomplete field with type selectors in case more than one pair of type selectors and autocomplete field used --------- Co-authored-by: Georgy Litvinov --- webapp/src/main/webapp/js/customFormUtils.js | 5 ++++- .../forms/js/customFormWithAutocomplete.js | 20 ++++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/webapp/src/main/webapp/js/customFormUtils.js b/webapp/src/main/webapp/js/customFormUtils.js index f60974bda..decddd4dc 100644 --- a/webapp/src/main/webapp/js/customFormUtils.js +++ b/webapp/src/main/webapp/js/customFormUtils.js @@ -70,6 +70,9 @@ vitro.customFormUtils = { }, capitalize: function(word) { - return word.substring(0, 1).toUpperCase() + word.substring(1); + if (word){ + return word.substring(0, 1).toUpperCase() + word.substring(1); + } + return ""; } } diff --git a/webapp/src/main/webapp/templates/freemarker/edit/forms/js/customFormWithAutocomplete.js b/webapp/src/main/webapp/templates/freemarker/edit/forms/js/customFormWithAutocomplete.js index 2b15ad9bd..689ae3d96 100644 --- a/webapp/src/main/webapp/templates/freemarker/edit/forms/js/customFormWithAutocomplete.js +++ b/webapp/src/main/webapp/templates/freemarker/edit/forms/js/customFormWithAutocomplete.js @@ -340,8 +340,14 @@ var customForm = { }, select: function(event, ui) { customForm.showAutocompleteSelection(ui.item.label, ui.item.uri, $(selectedObj)); - if ( $(selectedObj).attr('acGroupName') == customForm.typeSelector.attr('acGroupName') ) { - customForm.typeSelector.val(ui.item.msType); + let currAttr = $(selectedObj).attr('acgroupname'); + if (currAttr) { + for (const customTypeSelector of customForm.typeSelector ) { + let customTypeAttr = $(customTypeSelector).attr('acgroupname'); + if (customTypeAttr && currAttr === customTypeAttr) { + $(customTypeSelector).val(ui.item.msType); + } + } } } }); @@ -570,7 +576,15 @@ var customForm = { } else { $acSelectionObj = $(selectedObj); - customForm.typeSelector.val(''); + let currAttr = $(selectedObj).attr('acgroupname'); + if (currAttr) { + for (const customTypeSelector of customForm.typeSelector ) { + let customTypeAttr = $(customTypeSelector).attr('acgroupname'); + if (customTypeAttr && currAttr === customTypeAttr) { + $(customTypeSelector).val(''); + } + } + } } $acSelector = this.getAcSelector($acSelectionObj);