The last part of our Redux Form implementation is the validation. Using the previous recipe, let's add validation of the input task.
Implementing validation in a form
How to do it...
The validations are needed in any form, so let's add some validations to our fields:
- First, we need to modify our TodoForm.jsx and we need to create a validate function, where we need to validate if our task is not empty. We then need to create a renderError method to render our error message if we try to add an empty task, as shown in the following code:
import React, { Component } from 'react';
import { Field, reduxForm } from 'redux-form';
import './TodoForm.css';
class TodoForm extends Component {
renderInput...