-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Description
Describe the problem
We now have declarative form validation...
export const myform = form(schema, (data) => {
// `data` satisfies `schema`
});
...but there are some situations where validity can't be determined without attempting some action — e.g. if you check remaining stock inside the schema, the stock could change before the callback runs. It's unlikely, but possible.
Describe the proposed solution
Pass an invalid
function as the second argument to the callback. This function receives an array of issues
, and throws an error so that no further processing takes place (and, for example, the ongoing database transaction is rolled back).
The issues
array can be an array of Standard Schema issues (i.e. produced with a validation library), or an array of { message: string, name?: string }
objects. name
must correspond to one of the form fields (TypeScript will enforce this); if omitted, the resulting issue will only exist in the top-level issues.$
array.
Whichever type of issue is used, they are all normalized to RemoteFormIssue
.