mirror of
https://github.com/portainer/portainer.git
synced 2025-07-24 15:59:41 +02:00
fix(r2a): don't set errors to undefined [EE-6665] (#11059)
Some checks are pending
ci / build_images (map[arch:amd64 platform:linux]) (push) Waiting to run
ci / build_images (map[arch:amd64 platform:windows version:1809]) (push) Waiting to run
ci / build_images (map[arch:amd64 platform:windows version:ltsc2022]) (push) Waiting to run
ci / build_images (map[arch:arm64 platform:linux]) (push) Waiting to run
ci / build_manifests (push) Blocked by required conditions
/ triage (push) Waiting to run
Lint / Run linters (push) Waiting to run
Test / test-client (push) Waiting to run
Test / test-server (map[arch:amd64 platform:linux]) (push) Waiting to run
Test / test-server (map[arch:amd64 platform:windows version:1809]) (push) Waiting to run
Test / test-server (map[arch:amd64 platform:windows version:ltsc2022]) (push) Waiting to run
Test / test-server (map[arch:arm64 platform:linux]) (push) Waiting to run
Some checks are pending
ci / build_images (map[arch:amd64 platform:linux]) (push) Waiting to run
ci / build_images (map[arch:amd64 platform:windows version:1809]) (push) Waiting to run
ci / build_images (map[arch:amd64 platform:windows version:ltsc2022]) (push) Waiting to run
ci / build_images (map[arch:arm64 platform:linux]) (push) Waiting to run
ci / build_manifests (push) Blocked by required conditions
/ triage (push) Waiting to run
Lint / Run linters (push) Waiting to run
Test / test-client (push) Waiting to run
Test / test-server (map[arch:amd64 platform:linux]) (push) Waiting to run
Test / test-server (map[arch:amd64 platform:windows version:1809]) (push) Waiting to run
Test / test-server (map[arch:amd64 platform:windows version:ltsc2022]) (push) Waiting to run
Test / test-server (map[arch:arm64 platform:linux]) (push) Waiting to run
Co-authored-by: testa113 <testa113>
This commit is contained in:
parent
517190e28b
commit
9ad78753bc
3 changed files with 24 additions and 20 deletions
|
@ -17,6 +17,8 @@ interface FormFieldProps<TValue> {
|
|||
|
||||
type WithFormFieldProps<TProps, TValue> = TProps & FormFieldProps<TValue>;
|
||||
|
||||
type ValidationResult<T> = FormikErrors<T> | undefined;
|
||||
|
||||
/**
|
||||
* This utility function is used for wrapping React components with form validation.
|
||||
* When used inside an Angular form, it sets the form to invalid if the component values are invalid.
|
||||
|
@ -109,6 +111,7 @@ function createFormValidatorController<TFormModel, TData = never>(
|
|||
|
||||
this.handleChange = this.handleChange.bind(this);
|
||||
this.runValidation = this.runValidation.bind(this);
|
||||
this.validate = this.validate.bind(this);
|
||||
}
|
||||
|
||||
async handleChange(newValues: TFormModel) {
|
||||
|
@ -123,21 +126,31 @@ function createFormValidatorController<TFormModel, TData = never>(
|
|||
this.form?.$setValidity('form', true, this.form);
|
||||
|
||||
const schema = schemaBuilder(this.validationData);
|
||||
this.errors = undefined;
|
||||
const errors = await (isPrimitive
|
||||
? validateForm<{ value: TFormModel }>(
|
||||
() => object({ value: schema }),
|
||||
{ value }
|
||||
).then((r) => r?.value)
|
||||
: validateForm<TFormModel>(() => schema, value));
|
||||
this.errors = await this.validate(schema, value, isPrimitive);
|
||||
|
||||
if (errors && Object.keys(errors).length > 0) {
|
||||
this.errors = errors as FormikErrors<TFormModel> | undefined;
|
||||
if (this.errors && Object.keys(this.errors).length > 0) {
|
||||
this.form?.$setValidity('form', false, this.form);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async validate(
|
||||
schema: SchemaOf<TFormModel>,
|
||||
value: TFormModel,
|
||||
isPrimitive: boolean
|
||||
): Promise<ValidationResult<TFormModel>> {
|
||||
return this.$async(async () => {
|
||||
if (isPrimitive) {
|
||||
const result = await validateForm<{ value: TFormModel }>(
|
||||
() => object({ value: schema }),
|
||||
{ value }
|
||||
);
|
||||
return result?.value as ValidationResult<TFormModel>;
|
||||
}
|
||||
return validateForm<TFormModel>(() => schema, value);
|
||||
});
|
||||
}
|
||||
|
||||
async $onChanges(changes: {
|
||||
values?: { currentValue: TFormModel };
|
||||
validationData?: { currentValue: TData };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue