Skip to content

Commit

Permalink
Merge pull request #302 from effective-webwork/issue-1934
Browse files Browse the repository at this point in the history
#1934: FIS personal interface: Prevent overwriting of information in …
  • Loading branch information
Erikmitk authored Nov 1, 2024
2 parents 8b1480e + 8622f2b commit cd72992
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
1 change: 1 addition & 0 deletions Resources/Private/Partials/DocumentForm/Group.html
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
<button type="button"
title="{f:translate(key: 'form_button.add_item', arguments: {0: fieldItem.displayName})}"
name="add_field" class="btn btn-secondary add_field" data-field="{fieldItem.uid}"
data-group="{formGroupUid}"
data-ajax="{f:uri.action(action:'field',controller:'AjaxDocumentForm',pageType:ajaxTypeNum,arguments:{pageUid: formPageUid,groupUid: formGroupUid,groupIndex: groupIndex,fieldUid: fieldItem.uid})}"
data-index="{fieldItemIndex}">
<i class="fas fa-plus"></i>
Expand Down
6 changes: 3 additions & 3 deletions Resources/Public/JavaScript/kitodopublication.js
Original file line number Diff line number Diff line change
Expand Up @@ -2066,15 +2066,15 @@ var setDataRequest = function(url, dataId, context) {
var splitId = key.split("-");
// key without the last index (field index)
var keyWithoutFieldIndex = splitId[0] + '-' + splitId[1] + '-' + splitId[2] + '-' + splitId[3];
var isFieldRepeatable = $('.' + keyWithoutFieldIndex + '-' + '0').parent().parent().find('.add_field').length;
var isFieldRepeatable = $("button.add_field[data-group=" + splitId[1] + "][data-field=" + splitId[3] + "]").length;

if($('.' + key).length != 0 && $('.' + key).val() == '' || $('.' + key).length != 0 && $('.' + key).val() != '' && !isFieldRepeatable) {
// form field is empty and exists or form field is not empty and not repeatable, overwrite!
$('.' + key).val(data[key]).change();
} else if ($('.' + key).length != 0 && $('.' + key).val() != '' && isFieldRepeatable) {
// form field exists and is not empty
// add new form input
$('.' + keyWithoutFieldIndex + '-' + '0').parent().parent().find('.add_field').click();
$("button.add_field[data-group=" + splitId[1] + "][data-field=" + splitId[3] + "]").click();

// count repeated fields if not counted already
var k = newKeyMapping.get(keyWithoutFieldIndex);
Expand Down Expand Up @@ -2106,7 +2106,7 @@ var setDataRequest = function(url, dataId, context) {
newKeyMapping.set(keyWithoutFieldIndex, (k + 1));
}
// add new form input
$('.' + keyWithoutFieldIndex + '-' + '0').parent().parent().find('.add_field').click();
$("button.add_field[data-group=" + splitId[1] + "][data-field=" + splitId[3] + "]").click();
isElementLoaded('.' + key, datakey, function (element, fieldKey) {
$(element).val(data[fieldKey]).change();
});
Expand Down

0 comments on commit cd72992

Please sign in to comment.