An error occurred while validating Redux Form due to using field names such as user.name

In my React component, I have a Redux form structured like this:

<div className="col-sm-12">
 <div className="form-group row">
  <div className="col-sm-4">
   <label>A. Name</label>
  </div>
  <div className="col-sm-8">
  <ul className="sub-qn-ans-list d-flex list-unstyled">
    <li>
      <Field
      name="first_name"
      component={renderField}
      type="text"
      placeholder="First name"
      className="form-control" />
    </li>
    <li>
      <Field
      name="last_name"
      component={renderField}
      placeholder="Last name"
      type="text"
      className="form-control" />
    </li>
  </ul>
</div>
</div>
<div className="form-group row">
<div className="col-sm-4">
  <label>B. Residential Address</label>
</div>
<div className="col-sm-8">
  <ul className="sub-qn-ans-list d-flex list-unstyled">
    <li>
      <Field
        name="residential.street"
        component={renderField}
        placeholder="Street"
        type="text"
        className="form-control" />
    </li>
    ... (remaining code)

When trying to add validations for the input fields, validation works for first_name and last_name, but fails for residential.street.

Validation code snippet below:

const LocatorValidation = (values, form) => {
const errors = {};
if (!values.first_name) {
  errors.first_name = 'Required';
} else if (!/[A-Za-z.]+/.test(values.first_name)) {
  errors.first_name = 'First name must have only alphabets';
}
... (remaining validation code)

Error screenshot: https://i.stack.imgur.com/c4hvU.png

Answer №1

If the error message mentions that errors.residential.street is undefined, it means that the residential property of errors has not been set. You can resolve this by initializing it as an empty object first:

errors.residential = {}
errors.residential.street = "Required"

To enhance the validation, you could also consider checking for the presence of values in the residential street field:

!values.residential || !values.residential.street

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How can I insert a script into the head tag using Meteor and React?

Struggling to incorporate a script tag into my website, I am facing some difficulties. The guidelines recommending me to add it to the head tag of the site are proving to be challenging since I am using Meteor + React and lack any HTML pages with a head t ...

Using Cookies with Next.js and Vercel

I am facing an issue with my NextJs app deployed on Vercel where the cookie is not being set. Upon checking the console in Network, I can see that the request returns a 200 status and the set-cookie value is present without any warning. However, when I loo ...

Why won't the CSS update in Next.js when the local state variable changes on page load?

I seem to be facing an issue with a variable stored in localStorage that changes when using a toggle button. The color changes correctly upon toggling the button, but upon page refresh, it doesn't display the correct color saved in local storage. Eve ...

Can Reactstrap integrate seamlessly with Bootstrap version 5?

I encountered an error while using reactstrap, bootstrap, and nextjs Server Error SyntaxError: The requested module 'react-popper' is expected to be of type CommonJS, which does not support named exports. CommonJS modules can be imported by impor ...

Nginx deployment of React causes issues with AJAX Axios functionality

I am interested in integrating frontend with backend on cloud virtual machines such as DigitalOcean, AWS, or Microsoft Azure. Frontend: React Backend: Spring Spring MVC Mybatis + Tomcat (Excluding Spring Boot) After researching various methods using N ...

Having trouble executing a fetch request in Next.js

I am struggling to perform a fetch request using getStaticProps in Next.js. Despite following the documentation provided on their website, I am unable to console log the props successfully. My background is mainly in React, so I tried to adapt my approac ...

The useStyles function does not automatically update properties in response to changes in variables

I have encountered an issue where the style of a component is not changing based on a boolean state change until I refresh the page. Here's what I'm doing: Within my parent App component, I have the following code: import React from "react"; imp ...

Step-by-step guide on programmatically closing the Material-UI DropDownMenu

http://www.material-ui.com/#/components/dropdown-menu Having encountered a styling issue, I was compelled to rearrange the order of components within my material-ui DropdownMenu. Nevertheless, some buttons (renderNavLink) are now failing to close the Dro ...

React | Error: Build file blank during compilation

I am currently in the process of constructing and deploying a React app. After executing the build, when I attempt to open the index.html file from the build folder [see attached screenshot], it opens as a blank page. I have also tried adding "homepage": ...

Tips for minimizing API calls when validating the authenticity of a JWT token stored in a cookie

Upon a user logging in through my React frontend, an API call is made to the server side to generate a JWT token which is then sent back in a secure HTTP-only cookie. Subsequent API calls from the frontend include this cookie for verification on the server ...

Troubleshooting jsPDF problem with multi-page content in React and HTML: Converting HTML to PDF

I need to convert HTML content in my React application into a PDF file. My current approach involves taking an HTML container and executing the following code snippet: await htmlToImage .toPng(node) .then((dataUrl) => { ...

Executing functions in real-time using React Native

I'm fairly new to Object-Oriented Programming (OOP) and my understanding of promises, asynchronous/synchronous function execution is quite basic. Any guidance or help from your end would be greatly appreciated! Let's take a look at an example fr ...

An Axios request will consistently return a HTTP status code of 200

I have encountered an issue with a PUT request I am making. Despite receiving a 404 response from my express server, axios always sees it as 200. The correct response is shown in the express logs: PUT /v1/org/password/reset 404 339.841 ms - 71 This is th ...

What is the best way to set up distinct Jest test environments for React Components and Backend API routes within NextJs?

In the realm of testing with NextJS, Jest comes into play effortlessly, complemented by React Testing Library for frontend testing. Interestingly, Jest can also be utilized to test backend code. Currently, I am incorporating a library in my API routes tha ...

Is it possible to include array elements in a dropdown menu using React?

Imagine you have an array called const places = [" a1", "a2", "a3"]; and <FormControl variant="outlined" className={classes.formControl}> <InputLabel id="dropdown_label">Testing</InputL ...

Webpack's development server along with JSXHint is indicating that the constant named `$__0` has already been declared

After running the command below, it appears that jsxhint is analyzing the compiled files by webpack: webpack-dev-server --devtool eval --colors --progress --content-base ./build The warnings I receive are as follows: const '$__0' has already ...

Having trouble with integrating @rneui or react-native-vector-icons in React Native projects? You're not alone - many users have reported errors and project breakages

I have recently delved into the world of react native, although I am well-versed in other programming languages. My projects seem to be plagued by an abundance of errors, especially when it comes to installing new packages. While I have managed to workarou ...

What are the best ways to utilize React events in conjunction with Material-UI components?

Is there a way to use standard React events like onMouseLeave with the Material-UI DataGrid? The DataGrid exposes an onCellHover prop but lacks an event for when hovering ends. <DataGrid onMouseLeave={handleMouseLeave} /> Unfortunately, this does no ...

Issue with useState in Next.js when fetching data from an API

When attempting to retrieve data from the API, I am receiving a response. However, when trying to set the data to useState using the setAccessData function, the data is not being accessed properly. Despite trying multiple methods, the data continues to sho ...

The information retrieved from an API fails to populate the table on the NextJS platform

I am facing an issue while trying to populate a table using an API call in NextJS. I have used the getStaticProps function to retrieve the data and pass it to the component. However, when I attempted to use the map() function to iterate over the data objec ...