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
From the course: Building React and Django Apps
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
(Locked)
Handling creating models with Django REST framework1m 39s
-
(Locked)
Creating a REST API Service class with React and Axios2m 24s
-
(Locked)
Creating a basic form as a React component2m 22s
-
(Locked)
Creating form fields for basic form2m 6s
-
(Locked)
Connecting a React component to a service2m 26s
-
(Locked)
Validating form data with Django REST framework54s
-
(Locked)
Displaying validation errors with React1m 23s
-
(Locked)
-
-
-