1. 14
    Validate Form Fields in a Remix Action
    3m 25s

Validate Form Fields in a Remix Action

InstructorKent C. Dodds

Share this video with your friends

Send Tweet

Our posts form needs some kind of validation to prevent bad submissions from going through. We’ll want to start be validation sever-side since that is essential, and only do front-end validations as enhancement later.

We can do a validation in our action by creating an errors object that has three ternaries that check if any field is empty. Then we check if there are errors, and if there are, we return the errors as JSON instead of submitting the form and redirecting.

Then in our component we can use the errors data to display messages to the user.

ed leach
~ 2 years ago

Hello, on github there is no "new.tsx" in onewheel-blog/app/routes/posts/admin/ Is the complete code available somewhere? Thanks.

Lucas Minter
~ 2 years ago

The code in the repo is the finished code. The repo is the finished product. He changes the file name in a later lesson, Allow Admins to Edit Existing Posts on Remix Applications, to $slug.tsx so that it's dynamic like in the lesson Create a Dynamic Segment in Remix.

ed leach
~ 2 years ago

Thanks.