Skip to content

Commit 6939861

Browse files
committed
continue
1 parent 615a98c commit 6939861

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

packages/core/src/components/Form.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
ValidatorType,
3636
Experimental_DefaultFormStateBehavior,
3737
Experimental_CustomMergeAllOf,
38+
// FormValidation,
3839
} from '@rjsf/utils';
3940
import _forEach from 'lodash/forEach';
4041
import _get from 'lodash/get';
@@ -274,6 +275,8 @@ export default class Form<
274275
*/
275276
formElement: RefObject<any>;
276277

278+
private customValidationErrors: RJSFValidationError[] = [];
279+
277280
/** Constructs the `Form` from the `props`. Will setup the initial state from the props. It will also call the
278281
* `onChange` handler if the initially provided `formData` is modified to add missing default values as part of the
279282
* state construction.
@@ -519,6 +522,10 @@ export default class Form<
519522
return shouldRender(this, nextProps, nextState);
520523
}
521524

525+
// private customValidateCB = (formData: T | undefined, errors: FormValidation<T>, uiSchema?: UiSchema<T, S, F>): FormValidation<T> => {
526+
// const errorHandler = customValidate(newFormData, createErrorHandler<T>(newFormData), uiSchema);
527+
// };
528+
522529
/** Validates the `formData` against the `schema` using the `altSchemaUtils` (if provided otherwise it uses the
523530
* `schemaUtils` in the state), returning the results.
524531
*
@@ -703,8 +710,12 @@ export default class Form<
703710
errors = merged.errors;
704711
}
705712
// Merging 'newErrorSchema' into 'errorSchema' to display the custom raised errors.
713+
console.log('newErrorSchema****', newErrorSchema);
706714
if (newErrorSchema) {
707715
const filteredErrors = this.filterErrorsBasedOnSchema(newErrorSchema, retrievedSchema, newFormData);
716+
console.log('filteredErrors', filteredErrors);
717+
console.log('newFormData', newFormData);
718+
console.log('filteredErrors formData', formData);
708719
errorSchema = mergeObjects(errorSchema, filteredErrors, 'preventDuplicates') as ErrorSchema<T>;
709720
}
710721
state = {

packages/playground/src/components/Playground.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,13 @@ export default function Playground({ themes, validators }: PlaygroundProps) {
134134
window.alert('Form submitted');
135135
}, []);
136136

137+
const customValidate = (formData: any, errors: any) => {
138+
if (formData['Test'] > formData['Test2']) {
139+
errors['Test']?.addError('Validate error: Test should be LE than Test2');
140+
}
141+
return errors;
142+
};
143+
137144
return (
138145
<>
139146
<Header
@@ -189,7 +196,7 @@ export default function Playground({ themes, validators }: PlaygroundProps) {
189196
extraErrors={extraErrors}
190197
schema={schema}
191198
uiSchema={uiSchema}
192-
formData={formData}
199+
// formData={formData}
193200
fields={{
194201
geo: GeoPosition,
195202
'/schemas/specialString': SpecialInput,
@@ -201,6 +208,7 @@ export default function Playground({ themes, validators }: PlaygroundProps) {
201208
onFocus={(id: string, value: string) => console.log(`Focused ${id} with value ${value}`)}
202209
onError={(errorList: RJSFValidationError[]) => console.log('errors', errorList)}
203210
ref={playGroundFormRef}
211+
customValidate={customValidate}
204212
/>
205213
</DemoFrame>
206214
)}

0 commit comments

Comments
 (0)