Having trouble submitting a form with React and Formik

Here is the Model (popup) code I am using to send the user's email address to the backend service. The Model component is being rendered in my Login Component. However, I am facing an issue where I am unable to submit this form. Despite having working Yup validations, clicking on the "send" button does not trigger the onSubmit handler.

import React from 'react';
import { Formik, Field, Form, ErrorMessage } from 'formik';
import * as Yup from 'yup';
import { errorMessage } from '../../utility/error-messages';
import { Button, Modal, ModalBody, ModalFooter } from 'reactstrap';

const TextFieldComponent = (props) => {
return (
    <div className="formGroup">
    {props.touched &&
    props.touched[props.name] &&
    props.errors &&
    props.errors[props.name] !== undefined ? (
        <ErrorMessage
        name={props.name}
        render={(msg) => <label className="errorMessage">{msg}</label>}
        />
    ) : (
        <label htmlFor={props.name}>{props.label}</label>
    )}

    <Field
        name={props.name}
        type="text"
        className={
        props.touched &&
        props.touched[props.name] &&
        props.errors &&
        props.errors[props.name] !== undefined
            ? 'formControl error '
            : 'formControl'
        }
        onBlur={props.handleBlur}
        onChange={props.handleChange}
    />
    </div>
);
};

const setSchema = Yup.object({
email: Yup.string()
    .email(errorMessage.emailValidation)
    .required(errorMessage.emailRequired),
});

export const ForgetPasswordModal = ({ show = false, onClose = () => {} }) => {
debugger;
return (
    <>
    <Formik
        initialValues={{
        email: '',
        }}
        validationSchema={setSchema}
        onSubmit={(values, { setSubmitting }) => {
        setTimeout(() => {
            alert(JSON.stringify(values, null, 2));
            setSubmitting(false);
        }, 400);
        }}
    >
        {({ isSubmitting, errors, touched, handleChange, handleBlur }) => {
        return (
            <>
            <Form>
                <Modal
                className="forgetPassPopup resetPassword"
                isOpen={show}
                backdrop={'static'}
                centered
                fade
                >
                <ModalBody>
                    <h3>Reset password</h3>
                    <p>
                    Enter the email.
                    </p>
                    <div className="formGroup">
                    <TextFieldComponent
                        name="email"
                        label="email"
                        errors={errors}
                        touched={touched}
                        handleBlur={handleBlur}
                        handleChange={handleChange}
                    />
                    </div>
                </ModalBody>
                <ModalFooter>
                    <Button
                    className="btn btnSecondary"
                    onClick={() => onClose(false)}
                    >
                    Cancel
                    </Button>
                    <Button
                    type="submit"
                    disabled={isSubmitting}
                    className="btn btnPrimary"
                    >
                    Send
                    </Button>
                </ModalFooter>
                </Modal>
            </Form>
            </>
        );
        }}
    </Formik>
    </>
);
};

Answer №1

The issue could potentially be related to the Modal component placement. If the modal is within the form and a portal is utilized to render it, there's a possibility that it might be displayed outside the form. Have you considered placing the form inside the modal and testing if that resolves the problem?

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

execute a series of asynchronous functions one after another

async function cancelUserSubscriptionHandler() { const unsubscribe = await fetch("/api/stripe-sessions/cancel-subscription", { method: "PATCH", body: JSON.stringify(), headers: { "Content-Type": "appli ...

Having trouble with self-hosted font not displaying correctly in Material-UI?

I'm currently working on a Material-UI project and I'm trying to incorporate some custom self-hosted fonts that are not available as Google Fonts. Despite following all the guidelines in both Material-UI and JSS documentation, I have implemented ...

Transforming a React Class Component into a React Functional Component

After struggling for a day with multiple failed attempts, I have been unsuccessful in converting a React Class Component. The original class component code is as follows: class NeonCursor extends React.Component { constructor(props) { super(props); ...

"Pushing elements into an array does not function properly within a promise

I'm having trouble with my code - the push method isn't working and it's not returning anything. import {nearbyUsers, getLatitude, getLongitude} from './helper' const users = [] nearbyUsers(session, getLatitude(), getLongitude()).t ...

What is the best way to establish a state within a component?

How can I update the state of a component in ReactJS to show notifications again? import React, { useState } from 'react' const NotificationError = (props) => { const [notify, setNotify] = useState(false); console.log("notify.state: ...

What is the best way to assign a unique background color to each individual card in my card list?

I have a list of cards and I want to assign a unique color to each card in the list. I attempted to do this on my own, but it ended up being more complex than I anticipated. Here is the list of cards: return ( <Container> <Row className=&qu ...

The error at line 72 of proxyConsole.js is: TypeError - Unable to access the 'default' property of an undefined object

I am new to using react redux loading bar and redux forms After clicking a button, I want the loading bar to display. The issue arises when I try to load the loading bar, resulting in the following error message: proxyConsole.js:72 TypeError: Cannot read p ...

Finding the Earliest and Latest Date in Material UI DatePicker Component within a React Application

I am facing an issue with date selection based on the 'access' value in my code. When the 'access' value is 1, there should be no restrictions on selecting dates. However, when the value of 'access' is not 1, users should only ...

Retrieve a file from an Express API using React with the help of Axios

When working with a React client and an Express API, how can the React client download a file sent by the Express API? Issue: If I manually enter the URL into my browser's address bar and hit enter, the file downloads successfully. However, when I ...

Changing the color gradient of a range column chart in ApexCharts

Currently, I am working on a project where I am trying to incorporate a waterfall chart using ApexCharts. Unfortunately, the Waterfall chart is not readily available with ApexCharts, so I am experimenting with modifying the range column chart into a Waterf ...

How to handle an unexpected keyword 'true' error when using the `useState` hook in React?

Trying to set the open prop of the MUIDrawer component to true on user click is causing an error stating "Unexpected keyword 'true'" import React, { useState } from "react"; import { withRouter } from "react-router-dom"; impo ...

React opacity transition component not switching fade direction

I'm in the process of developing a compact component that smoothly transitions between its child elements when triggered by one of its methods. I have been referencing this code for guidance, but I am aiming to make it compatible with any number of ch ...

I am experiencing an issue with my React app deployed on Heroku where it successfully loads the home page but fails

My react application performs perfectly when run locally and is successfully deployed on heroku. However, upon clicking any link from the home page to another page, a blank page with 'not found' message appears. No other error messages are displa ...

Steps for integrating global components in Next.jsWant to learn how to seamlessly incorporate a list

Just diving into Nextjs and looking to streamline the process of adding a list of components and utilities to all my pages without having to import them individually. How can I make these assets globally available in my components? Additionally, some util ...

Controlling the access to simpleJWT tokens in Django-React authentication to restrict user permissions

My backend has two React frontends: one for general users and the other specifically for admin users with the is_staff attribute. I have customized TokenObtainPairSerializer to add extra fields like 'is_staff'. Now, I'm considering how to r ...

React components do not re-render when the context value changes

The issue with React not re-rendering when the context value changes persists I am using tailwindcss, React(v18.2.0), and vite(3.2.4). I have already attempted i want that clicking on TodoItem should change the completed value in the todo using React con ...

Delete the text in MUI's TablePagination component that displays the number of rows per page and the total rows in the table

Currently, I am integrating MUI's tablePagination component into my React table with TypeScript. I am looking to remove/disable the circlemarked text displayed in the image (the picture is an example from MUI). https://i.stack.imgur.com/ib0t2.png Af ...

Implementing Immer in Typescript

Recently, I've been exploring the possibility of integrating Immer into my React project that already utilizes Typescript. Unfortunately, I haven't been able to discover a clear guide on how to effectively employ Immer in conjunction with Typescr ...

The property 'remove' cannot be accessed because it is either undefined or null

Based on the client-side error logs I've reviewed, it seems that a TypeError is occurring in my ReactJS application at times. The exception being thrown is as follows: TypeError: Unable to get property 'remove' of undefined or null referenc ...

Material UI autocomplete with multiple selection

I am attempting to maintain state for a multi-select Autocomplete by using an array of strings. However, I also need an array of objects to store the relationship between the strings representing state on the backend and the labels for display. In this sce ...