@streamscloud/kit 0.41.1 → 0.42.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -33,6 +33,13 @@ export declare class FormValidationHandler<T extends TypeToValidate<T> = TypeToV
|
|
|
33
33
|
updateValidateField: <K extends keyof T>(field: K, value: T[K]) => Promise<void>;
|
|
34
34
|
updateTouched: (field: keyof T, value: boolean) => void;
|
|
35
35
|
updateTouchedForAllFields: (value: boolean) => void;
|
|
36
|
+
/**
|
|
37
|
+
* Sets an error the schema can't produce (a server-side rejection), marking the field touched so it renders.
|
|
38
|
+
* The next validation pass overwrites it — `validateField` (blur by default), `validate()`, `handleSubmit`.
|
|
39
|
+
*/
|
|
40
|
+
setFieldError: (field: keyof T, message: string) => void;
|
|
41
|
+
/** Batch {@link setFieldError} — skips `undefined` entries, same overwrite-on-next-validation semantics. */
|
|
42
|
+
setFieldErrors: (errors: Partial<Record<keyof T, string>>) => void;
|
|
36
43
|
validateField: (field: keyof T) => Promise<void>;
|
|
37
44
|
updateInitialValues: (newValues: T) => void;
|
|
38
45
|
updateValidator: (validator: IFormHandlerValidator<T>) => void;
|
|
@@ -75,6 +75,24 @@ export class FormValidationHandler {
|
|
|
75
75
|
ValidationUtils.update(this._touched, key, value);
|
|
76
76
|
});
|
|
77
77
|
};
|
|
78
|
+
/**
|
|
79
|
+
* Sets an error the schema can't produce (a server-side rejection), marking the field touched so it renders.
|
|
80
|
+
* The next validation pass overwrites it — `validateField` (blur by default), `validate()`, `handleSubmit`.
|
|
81
|
+
*/
|
|
82
|
+
setFieldError = (field, message) => {
|
|
83
|
+
ValidationUtils.update(this._errors, field, message);
|
|
84
|
+
this.updateTouched(field, true);
|
|
85
|
+
};
|
|
86
|
+
/** Batch {@link setFieldError} — skips `undefined` entries, same overwrite-on-next-validation semantics. */
|
|
87
|
+
setFieldErrors = (errors) => {
|
|
88
|
+
Object.keys(errors).forEach((field) => {
|
|
89
|
+
const message = errors[field];
|
|
90
|
+
if (message === undefined) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
this.setFieldError(field, message);
|
|
94
|
+
});
|
|
95
|
+
};
|
|
78
96
|
validateField = async (field) => {
|
|
79
97
|
return await this.validateFieldValue(field);
|
|
80
98
|
};
|