Submits a given FieldTree
using the given action function and applies any server errors
resulting from the action to the field. Server errors returned by the action
will be integrated
into the field as a ValidationError
on the sub-field indicated by the field
property of the
server error.
submit
Promise<void>
Submits a given FieldTree
using the given action function and applies any server errors
resulting from the action to the field. Server errors returned by the action
will be integrated
into the field as a ValidationError
on the sub-field indicated by the field
property of the
server error.
@paramaction
(form: FieldTree<TValue>) => Promise<TreeValidationResult>
An asynchronous action used to submit the field. The action may return server errors.
@returns
Promise<void>
Usage Notes
async function registerNewUser(registrationForm: FieldTree<{username: string, password: string}>) { const result = await myClient.registerNewUser(registrationForm().value()); if (result.errorCode === myClient.ErrorCode.USERNAME_TAKEN) { return [{ field: registrationForm.username, error: {kind: 'server', message: 'Username already taken'} }]; } return undefined;}const registrationForm = form(signal({username: 'god', password: ''}));submit(registrationForm, async (f) => { return registerNewUser(registrationForm);});registrationForm.username().errors(); // [{kind: 'server', message: 'Username already taken'}]
Jump to details