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 <georgy.litvinov@tib.eu>
This commit is contained in:
Georgy Litvinov 2023-02-02 14:24:47 +01:00 committed by GitHub
parent 81e12cc492
commit 509e9cf22b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 4 deletions

View file

@ -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 "";
}
}

View file

@ -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);