this.cephfsSubvolumeService,
null,
null,
- this.fsName
+ this.fsName,
+ this.activeGroupName
)
],
required: true,
name: 'groupName',
value: this.activeGroupName,
label: $localize`Group name`,
+ valueChangeListener: true,
+ dependsOn: 'cloneName',
typeConfig: {
options: allGroups
}
}
],
submitButtonText: $localize`Create Clone`,
+ updateAsyncValidators: (value: any) =>
+ CdValidators.unique(
+ this.cephfsSubvolumeService.exists,
+ this.cephfsSubvolumeService,
+ null,
+ null,
+ this.fsName,
+ value
+ ),
onSubmit: (value: any) => {
this.cephfsSubvolumeService
.createSnapshotClone(
submitButtonText: string;
onSubmit: Function;
+ updateAsyncValidators?: Function;
+
// Internal
formGroup: CdFormGroup;
if (field.asyncValidators) {
asyncValidators = asyncValidators.concat(field.asyncValidators);
}
- return new UntypedFormControl(
+
+ const control = new UntypedFormControl(
_.defaultTo(
field.type === 'binary' ? this.dimlessBinaryPipe.transform(field.value) : field.value,
null
),
{ validators, asyncValidators }
);
+
+ if (field.valueChangeListener) {
+ control.valueChanges.subscribe((value) => {
+ const validatorToUpdate = this.updateAsyncValidators(value);
+ this.updateValidation(field.dependsOn, validatorToUpdate);
+ });
+ }
+ return control;
}
getError(field: CdFormModalFieldConfig): string {
this.onSubmit(values);
}
}
+
+ updateValidation(name?: string, validator?: AsyncValidatorFn[]) {
+ const field = this.formGroup.get(name);
+ field.setAsyncValidators(validator);
+ field.updateValueAndValidity();
+ }
}
validators: ValidatorFn[];
asyncValidators?: AsyncValidatorFn[];
+ // Used when you want to dynamically update the
+ // async validators based on the field value
+ valueChangeListener?: boolean;
+ dependsOn?: string;
+
// --- Specific field properties ---
typeConfig?: {
[prop: string]: any;