From the course: Building React and Django Apps

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Displaying validation errors with React

Displaying validation errors with React

From the course: Building React and Django Apps

Start my 1-month free trial

Displaying validation errors with React

- [Instructor] Now that we're attaching validation errors, we can display them in the checkout page. We add the list of errors to the component's state. Then, whenever we place an order, we clear out the validation errors if the order is placed successfully, or we will be displaying those validation errors if the order is not placed successfully. Then when we render the checkout form we will need to extract the validation errors from the state and build up the list of errors that we will display. We're going to check each field that we have to see if there's an error for it. If there is an error we're going to add it to the list and then we're going to insert that list of errors right before we display the form fields. Now let's run the dev servers. Let's add a package to the cart and try and reserve it. If we click place order, it will show the usual error messages that none of the fields can be blank. We fill them out…

Contents