Skip to main content
Version: Current (v7.0.0-beta.3)

The ref's validate() takes only the data

Detect​

  • In your code, a call to formRef.current.validate(data, ...) that passes anything after the data.
  • The type checker reports Expected 1 arguments, but got 2. (or 3, 4) on that call.

Change​

validate() now takes only the data to validate: validate(formData). Its schema, altSchemaUtils and retrievedSchema parameters are gone. The ref is typed FormRef<T>; see A ref to Form holds a FormRef handle.

To validate against another schema or validator, build the utilities for it and call its validator yourself, passing the form's customValidate, transformErrors and uiSchema as validate() did:

-const { errors } = formRef.current.validate(data, otherSchema, otherSchemaUtils);
+const { errors } = otherSchemaUtils
+ .getValidator()
+ .validateFormData(data, otherSchema, customValidate, transformErrors, uiSchema);

To hand customValidate the same defaults the form would, pass the trailing getCustomValidateFormData that validateFormData() now takes: () => otherSchemaUtils.getDefaultFormState(otherSchema, data, true, undefined, uiSchema).

validate() also added the errors of ui:required fields on top. For those, merge otherSchemaUtils.getUiRequiredErrorSchema(uiSchema, data) into the result with validationDataMerge().

Verify​

  • The type checker accepts every validate() call.
  • Validating against the other schema reports the same errors, ui:required ones included, that the old call did.

Also read: