Fix multiplicty bug on Admin Template Editor.

This commit is contained in:
Kristian Ntavidi 2021-10-20 13:41:04 +03:00
parent 8e2fea2ea0
commit ae0618d5be
2 changed files with 17 additions and 16 deletions

View File

@ -379,7 +379,7 @@
<mat-checkbox class="fieldset-checkbox-action-dataset-profile-editor" [formControl]="this.form.get('hasCommentField')" [matTooltip]="'DATASET-PROFILE-EDITOR.ACTIONS.FIELDSET.INCLUDE-COMMENT-FIELD' | translate">{{'DATASET-PROFILE-EDITOR.ACTIONS.FIELDSET.COMMENT-FIELD' | translate}}</mat-checkbox>
</li>
<li class="list-inline-item">
<mat-checkbox class="fieldset-checkbox-action-dataset-profile-editor" [checked]="isMultiplicityEnabled" (change)="onIsMultiplicityEnabledChange($event)" [matTooltip]="'DATASET-PROFILE-EDITOR.ACTIONS.FIELDSET.ENABLE-MULTIPLICITY' | translate" [disabled]="viewOnly">
<mat-checkbox class="fieldset-checkbox-action-dataset-profile-editor" [(checked)]="isMultiplicityEnabled" (change)="onIsMultiplicityEnabledChange($event)" [matTooltip]="'DATASET-PROFILE-EDITOR.ACTIONS.FIELDSET.ENABLE-MULTIPLICITY' | translate" [disabled]="viewOnly">
{{'DATASET-PROFILE-EDITOR.ACTIONS.FIELDSET.MULTIPLICITY' | translate}}
</mat-checkbox>
</li>

View File

@ -1,4 +1,4 @@
import {Component, Input, OnChanges, OnInit, ViewChild} from '@angular/core';
import {Component, Input, OnChanges, OnInit, SimpleChanges, ViewChild} from '@angular/core';
import {AbstractControl, FormArray, FormControl, FormGroup} from '@angular/forms';
import {FieldEditorModel} from '../../../admin/field-editor-model';
import {Guid} from '@common/types/guid';
@ -118,6 +118,7 @@ export class DatasetProfileEditorCompositeFieldComponent extends BaseComponent i
private myCustomValidators:EditorCustomValidators = new EditorCustomValidators();
isMultiplicityEnabled = false;
constructor(
private dialog: MatDialog,
private language: TranslateService,
@ -127,11 +128,21 @@ export class DatasetProfileEditorCompositeFieldComponent extends BaseComponent i
super();
}
ngOnChanges(){
ngOnChanges(changes: SimpleChanges){
// this.setTargetField(null);
// this.showExtendedDescription = !!this.form.get('extendedDescription').value;
// this.showAdditionalInfo = !!this.form.get('additionalInformation').value;
console.log(this.form.get('fields')['controls'])
// console.log(this.form.get('fields')['controls'])
if( changes['form']){
try{
const multiplicity = this.form.get('multiplicity').value;
this.isMultiplicityEnabled = multiplicity.min > 0 || multiplicity.max >0;
} catch{
this.isMultiplicityEnabled = false;
}
}
}
get firstField(){
@ -142,17 +153,7 @@ export class DatasetProfileEditorCompositeFieldComponent extends BaseComponent i
}
}
get isMultiplicityEnabled(){
if(!this.form.get('multiplicity')){
return false;
}
if (this.form.get('multiplicity').value.min > 0 || this.form.get('multiplicity').value.max > 0) {
return true;
}
return false;
}
ngOnInit() {
@ -381,7 +382,6 @@ export class DatasetProfileEditorCompositeFieldComponent extends BaseComponent i
}
onIsMultiplicityEnabledChange(isMultiplicityEnabled: MatCheckboxChange) {
const multiplicity = this.form.get('multiplicity') as FormGroup;
const minControl = multiplicity.get('min');
@ -395,6 +395,7 @@ export class DatasetProfileEditorCompositeFieldComponent extends BaseComponent i
maxControl.setValue(0);
}
this.isMultiplicityEnabled = isMultiplicityEnabled.checked;
minControl.updateValueAndValidity();
maxControl.updateValueAndValidity();