Ready to get started?

Join Adocasts Plus for $8/mo, or sign into an existing Adocasts Plus account, to get access to all of our lessons.

robot mascot smiling

The useForm Helper

@tomgobich
Published by
@tomgobich
In This Lesson

We'll introduce the useForm helper composable provided by InertiaJS. We'll refactor our current form to use the useForm helper instead and see how it can help manage our form state, errors, and submission.

Chapters

00:00 - Refactoring to make use of the useForm helper
02:25 - Checking for errors from for form
03:15 - Normalizing our errors to a comma-delimited string
05:28 - Adding a loading indicator when our form is processing
07:00 - Clearing form values after successful submission

Join the Discussion 4 comments

Create a free account to join in on the discussion
  1. @gribbl

    Hi! Just wanted to share that a new update for @adonisjs/inertia has been released. You no longer need to declare errors in the Inertia config, and errors are now returned as a single string instead of an array of strings.

    3
    1. Responding to gribbl
      @tomgobich

      Yes, thank you for sharing!! Once completed, we'll be adding a new module to the end of this series covering what's new in Inertia v2 and the AdonisJS adapter and I'll circle back and add/edit some lessons to include notes for outdated things like this.

      2
  2. @inox

    Just my finding about @adonisjs/inertia update is that if you are using react and you consume errors via form.erros you must send post request using form.post otherwise (if you use router.post errors) it always empty (I think they not sync with props.errors )

    1
    1. Responding to inox
      @tomgobich

      Hi inox! Yes, that's correct! You have to send the request via the useForm composable in order for that composable to be able to digest any validation errors into its state.

      0