mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-07 10:04:11 +00:00
Fix issue with patch operations related to repeatable fields
This commit is contained in:
@@ -6,7 +6,8 @@ import {
|
|||||||
DYNAMIC_FORM_CONTROL_TYPE_GROUP,
|
DYNAMIC_FORM_CONTROL_TYPE_GROUP,
|
||||||
DynamicFormArrayGroupModel,
|
DynamicFormArrayGroupModel,
|
||||||
DynamicFormControlEvent,
|
DynamicFormControlEvent,
|
||||||
DynamicFormControlModel, isDynamicFormControlEvent
|
DynamicFormControlModel,
|
||||||
|
isDynamicFormControlEvent
|
||||||
} from '@ng-dynamic-forms/core';
|
} from '@ng-dynamic-forms/core';
|
||||||
|
|
||||||
import { hasValue, isNotEmpty, isNotNull, isNotUndefined, isNull, isUndefined } from '../../../shared/empty.util';
|
import { hasValue, isNotEmpty, isNotNull, isNotUndefined, isNull, isUndefined } from '../../../shared/empty.util';
|
||||||
@@ -299,7 +300,7 @@ export class SectionFormOperationsService {
|
|||||||
|
|
||||||
if (event.context && event.context instanceof DynamicFormArrayGroupModel) {
|
if (event.context && event.context instanceof DynamicFormArrayGroupModel) {
|
||||||
// Model is a DynamicRowArrayModel
|
// Model is a DynamicRowArrayModel
|
||||||
this.handleArrayGroupPatch(pathCombiner, event, (event as any).context.context);
|
this.handleArrayGroupPatch(pathCombiner, event, (event as any).context.context, previousValue);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -368,7 +369,7 @@ export class SectionFormOperationsService {
|
|||||||
|
|
||||||
if (event.context && event.context instanceof DynamicFormArrayGroupModel) {
|
if (event.context && event.context instanceof DynamicFormArrayGroupModel) {
|
||||||
// Model is a DynamicRowArrayModel
|
// Model is a DynamicRowArrayModel
|
||||||
this.handleArrayGroupPatch(pathCombiner, event, (event as any).context.context);
|
this.handleArrayGroupPatch(pathCombiner, event, (event as any).context.context, previousValue);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -498,23 +499,37 @@ export class SectionFormOperationsService {
|
|||||||
event: DynamicFormControlEvent,
|
event: DynamicFormControlEvent,
|
||||||
previousValue: FormFieldPreviousValueObject) {
|
previousValue: FormFieldPreviousValueObject) {
|
||||||
|
|
||||||
return this.handleArrayGroupPatch(pathCombiner, event.$event, (event as any).$event.arrayModel);
|
return this.handleArrayGroupPatch(pathCombiner, event.$event, (event as any).$event.arrayModel, previousValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Specific patch handler for a DynamicRowArrayModel.
|
* Specific patch handler for a DynamicRowArrayModel.
|
||||||
* Configure a Patch ADD with the current array value.
|
* Configure a Patch ADD with the current array value.
|
||||||
* @param pathCombiner
|
* @param pathCombiner
|
||||||
|
* the [[JsonPatchOperationPathCombiner]] object for the specified operation
|
||||||
* @param event
|
* @param event
|
||||||
|
* the [[DynamicFormControlEvent]] for the specified operation
|
||||||
* @param model
|
* @param model
|
||||||
|
* the [[DynamicRowArrayModel]] model
|
||||||
|
* @param previousValue
|
||||||
|
* the [[FormFieldPreviousValueObject]] for the specified operation
|
||||||
*/
|
*/
|
||||||
private handleArrayGroupPatch(pathCombiner: JsonPatchOperationPathCombiner,
|
private handleArrayGroupPatch(pathCombiner: JsonPatchOperationPathCombiner,
|
||||||
event,
|
event,
|
||||||
model: DynamicRowArrayModel) {
|
model: DynamicRowArrayModel,
|
||||||
|
previousValue: FormFieldPreviousValueObject) {
|
||||||
|
|
||||||
const arrayValue = this.formBuilder.getValueFromModel([model]);
|
const arrayValue = this.formBuilder.getValueFromModel([model]);
|
||||||
const segmentedPath2 = this.getFieldPathSegmentedFromChangeEvent(event);
|
const segmentedPath = this.getFieldPathSegmentedFromChangeEvent(event);
|
||||||
this.operationsBuilder.add(
|
if (isNotEmpty(arrayValue)) {
|
||||||
pathCombiner.getPath(segmentedPath2),
|
this.operationsBuilder.add(
|
||||||
arrayValue[segmentedPath2], false);
|
pathCombiner.getPath(segmentedPath),
|
||||||
|
arrayValue[segmentedPath],
|
||||||
|
false
|
||||||
|
);
|
||||||
|
} else if (previousValue.isPathEqual(this.formBuilder.getPath(event.model))) {
|
||||||
|
this.operationsBuilder.remove(pathCombiner.getPath(segmentedPath));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user