#Activate onChange validation only after submitting once?

8 messages · Page 1 of 1 (latest)

storm cliff
#
useForm({
...
    validators: {
      onChange: ({ formApi }) =>
        formApi.state.submissionAttempts > 0 ? loginSchema : undefined,
      onSubmit: loginSchema,
...

this doesn't seem to work

empty shoal
storm cliff
#

is there a way to achieve the same StandardSchema behaviour conditionally?

#

As in not having to manually return the error object?

#

I got it to work but it seems hacky

#
useForm({
    ...
    validators: {
      onChange: ({ value, formApi }) => {
        if (formApi.state.submissionAttempts > 0) {
          return standardSchemaValidators.validate(
            {
              value,
              validationSource: "form",
            },
            loginSchema
          );
        }
        return undefined;
      },
      onSubmit: loginSchema,
    ...
#

I think there should be a better example of using standardSchemaValidators

#

I might make a PR for the example