Skip to content

Commit eeedbed

Browse files
committed
feat:Replace extraErrorsBlockSubmit with extraErrorsAreWarnings
1 parent 1f7541d commit eeedbed

2 files changed

Lines changed: 26 additions & 6 deletions

File tree

packages/core/src/components/Form.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,8 @@ export interface FormProps<T = any, S extends StrictRJSFSchema = RJSFSchema, F e
173173
* still submit the form when these are the only errors displayed to the user.
174174
*/
175175
extraErrors?: ErrorSchema<T>;
176-
/** If set to true, causes the `extraErrors` to become blocking when the form is submitted */
177-
extraErrorsBlockSubmit?: boolean;
176+
/** If set to true, treats `extraErrors` as warnings instead of blocking form submission */
177+
extraErrorsAreWarnings?: boolean;
178178
/** If set to true, turns off HTML5 validation on the form; Set to `false` by default */
179179
noHtml5Validate?: boolean;
180180
/** If set to true, turns off all validation. Set to `false` by default
@@ -1216,14 +1216,14 @@ export default class Form<
12161216
* @returns - True if the form is valid, false otherwise.
12171217
*/
12181218
validateFormWithFormData = (formData?: T): boolean => {
1219-
const { extraErrors, extraErrorsBlockSubmit, focusOnFirstError, onError } = this.props;
1219+
const { extraErrors, focusOnFirstError, onError, extraErrorsAreWarnings } = this.props;
12201220
const { errors: prevErrors } = this.state;
12211221
const schemaValidation = this.validate(formData);
12221222
let errors = schemaValidation.errors;
12231223
let errorSchema = schemaValidation.errorSchema;
12241224
const schemaValidationErrors = errors;
12251225
const schemaValidationErrorSchema = errorSchema;
1226-
const hasError = errors.length > 0 || (extraErrors && extraErrorsBlockSubmit);
1226+
const hasError = errors.length > 0 || (extraErrors && extraErrorsAreWarnings !== true);
12271227
if (hasError) {
12281228
if (extraErrors) {
12291229
const merged = validationDataMerge(schemaValidation, extraErrors);

packages/core/test/Form.test.tsx

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2567,7 +2567,7 @@ describeRepeated('Form common', (createFormComponent) => {
25672567
onError,
25682568
focusOnFirstError,
25692569
extraErrors,
2570-
extraErrorsBlockSubmit: true,
2570+
extraErrorsAreWarnings: false,
25712571
});
25722572

25732573
const input = node.querySelector<HTMLInputElement>('input[type=text]')!;
@@ -4471,11 +4471,31 @@ describe('Async errors', () => {
44714471
},
44724472
} as unknown as ErrorSchema;
44734473

4474-
const { node, onSubmit } = createFormComponent({ schema, extraErrors });
4474+
const { node, onSubmit } = createFormComponent({ schema, extraErrors, extraErrorsAreWarnings: true });
44754475
fireEvent.submit(node);
44764476
expect(onSubmit).toHaveBeenCalledTimes(1);
44774477
});
44784478

4479+
it('should block submit by default when extraErrors are present', () => {
4480+
const onError = jest.fn();
4481+
const onSubmit = jest.fn();
4482+
const extraErrors = {
4483+
__errors: ['blocking error'],
4484+
} as ErrorSchema;
4485+
4486+
const { node } = createFormComponent({
4487+
schema: {},
4488+
onError,
4489+
onSubmit,
4490+
extraErrors,
4491+
// No extraErrorsAreWarnings prop, so should block by default
4492+
});
4493+
4494+
fireEvent.submit(node);
4495+
expect(onSubmit).not.toHaveBeenCalled();
4496+
expect(onError).toHaveBeenCalled();
4497+
});
4498+
44794499
it('should reset when props extraErrors changes and noValidate is true', () => {
44804500
const schema: RJSFSchema = {
44814501
type: 'object',

0 commit comments

Comments
 (0)