Skip to content

Commit

Permalink
Merged in task/dspace-cris-2023_02_x/DSC-1823 (pull request DSpace#2343)
Browse files Browse the repository at this point in the history
Task/dspace cris 2023 02 x/DSC-1823

Approved-by: Andrea Barbasso
  • Loading branch information
Simone-Ramundi authored and Andrea Barbasso committed Oct 10, 2024
2 parents 3c39a3d + f130702 commit ccbe6ae
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@
<!-- In case of repeatable fields show empty space for all elements except the first -->
<!-- In case of not repeatable field with multiple values show empty space for all elements except the last -->
<div *ngIf="(context?.index !== null && (!showErrorMessages || errorMessages.length === 0)) || (!hasHint && !showErrorMessages) ||
(!model.hideErrorMessages && showErrorMessages && !(!(model?.isModelOfNotRepeatableGroup) || model?.isModelOfNotRepeatableGroup && context?.index === context?.context?.groups?.length - 1))"
(!model.hideErrorMessages && showErrorMessages && !(!(model?.isModelOfNotRepeatableGroup) || model?.isModelOfNotRepeatableGroup && context?.index === context?.context?.groups?.length - 1)) && isNotRequiredGroupAndEmpty()"
class="clearfix w-100 mb-2"></div>

<!-- In case of not repeatable field with multiple values show error message for the last element only -->
<div
*ngIf="!model.hideErrorMessages && showErrorMessages && (!(model?.isModelOfNotRepeatableGroup) || model?.isModelOfNotRepeatableGroup && context?.index === context?.context?.groups?.length - 1)"
*ngIf="!model.hideErrorMessages && showErrorMessages && (!(model?.isModelOfNotRepeatableGroup) || model?.isModelOfNotRepeatableGroup && context?.index === context?.context?.groups?.length - 1) && isNotRequiredGroupAndEmpty()"
[id]="id + '_errors'"
[ngClass]="[getClass('element', 'errors'), getClass('grid', 'errors')]">
<small *ngFor="let message of errorMessages"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -581,4 +581,20 @@ export class DsDynamicFormControlContainerComponent extends DynamicFormControlCo
}
}

isNotRequiredGroupAndEmpty(): boolean {
const parent = this.model.parent;

if (hasValue(parent) && parent.type === 'GROUP') {

const groupHasSomeValue = parent.group.some(elem => !!elem.value);

if (!groupHasSomeValue && !parent.isRequired && parent.group?.length > 1) {
this.group.reset();
}

return (groupHasSomeValue && !parent.isRequired) || (hasValue(parent.isRequired) && parent.isRequired);
} else {
return true;
}
}
}

0 comments on commit ccbe6ae

Please sign in to comment.