github airjp73/rvf v8.0.0
RVF v8: Small, rarely-breaking changes

26 days ago

v8

This release contains some incremental changes that are only breaking in rare situations. In addition to that we have a couple small API additions.

New features

Experimental unstable_setCustomError API

The FormApi now has an experimental API unstable_setCustomError. The documentation for that is in the JS docs attached to the method itself. Please give it a try and feel free to give feedback! But do keep in mind this is an unstable API and may change before the final release.

Also worth noting that we don't yet have an API to set custom errors server-side, only the client-side API. Ideas for how that might API might look are welcome!

Added a keepError option to resetField

When I have time, I'd like to reach feature parity with the options object passed to resetField from react-hook-form. For now, I've just added keepError. If you'd like to help add the remaining options, please feel free to reach out and/or file a PR!

New options for the cancelSubmit API in onBeforeSubmit

The two new options are shouldFocusErrors and shouldCallOnInvalidSubmit. You can read more about these in the documentation here.

Breaking changes

These breaks are small, and likely won't affect the majority of use-cases.

noValidate when hydrated by default

In the old recommendations on supporting users without JS, there was a note about adding noValidate to the form element after hydration. This is now the default.

The reason for this change is to better support the useNativeValidity and useNativeValidityForForm hooks.
When these hooks are used without noValidate, RVF isn't able to perform validations on submit because the native validation errors block the submission.

This is especially problematic with the new custom errors API because an anticipated use-case is setting & clearing custom errors during onBeforeSubmit.

If you have a use-case where you need noValidate to be false, you can override this behavior by passing the prop to your form after calling getFormProps.

<form {...form.getFormProps()} noValidate={false} />

In onBeforeSubmit getValidatedData now correctly focuses invalid fields when it fails

When using the onBeforeSubmit callback, the getValidatedData api is used to run form validations and get the result. If validation fails, it throws and aborts the submit. The intention is for validation errors thrown this way to behave exactly as they would if you weren't using onBeforeSubmit.

Under the hood, this calls cancelSubmit({ shouldFocusErrors: true, shouldCallInvalidSubmit: true }). If your use-cases requires the old behavior, you can catch the cancellation error thrown by getValidatedData and call cancelSubmit yourself with the correct options.

PRs merged

These are all the PRs merged since the last release notes, though some of these have been released for awhile in patch releases.

New Contributors

Full Changelog: 7.0.1...v8.0.0

Don't miss a new rvf release

NewReleases is sending notifications on new releases.