Questions tagged [formik]

Formik revolutionizes form handling in both React and React Native, offering an exceptional form library.

Issue with DatePicker requiring 2 clicks to update, Formik along with Yup involved

I'm having an issue with my Material UI DatePicker: <Grid item xs={12}> <LocalizationProvider dateAdapter={AdapterDayjs}> <DatePicker ...

Refresh Search Suggestions in React Material Design Interface

Is there a way to reset the state_id when I select a value from the Autocomplete for city_id? Currently, it doesn't clear out automatically. If you want to see the code in action, please click on the link below: CLICK HERE CODE <Autocomple ...

Building a secure, highly nested object in Prisma

I am currently utilizing a data structure in Prisma and Nextjs that includes authentication via Next-Auth. The structure is as follows: user |-->profile |-->log |-->sublog At the moment, CRUD operations are being sent to the datab ...

Removing error messages upon form reset initiated by an API request

Is there a way to clear error messages that appear beneath a text field when resetting form fields with values from an api call? In my Formik form, I have three fields that are loaded from an api database call along with a Reset button that reloads these ...

Tips for retrieving values from a field prior to form submission using mui and formik

I need to access the value of a field before submitting the form in order to verify it. I tried using the onChange event for this purpose, but the field remains empty and the value is not displayed. My stack includes Mui and Formik. This is the initial se ...

Error message "findDOMNode is deprecated" occurs when a React application displays a form within a dialog box

I have encountered two issues with my React app. The parent component contains a button that, when clicked, displays a simple dialog with a text input and a submit button. Strict mode is enabled. The problems I am facing are: The initial value set for the ...

Unable to finalize submission of TextField using Formik

I am struggling to understand why one approach works and the other does not. One approach that works can be found here: pastebin. However, the second approach found here: pastebin does not work. The main difference between these two approaches is that in ...

Validation can include ensuring that strings in an array are in lowercase and not mandatory

Validation needed for an array of strings (tags). The strings should be in lowercase, maximum 14 characters long, and not required. I attempted to implement this validation, however, I need to modify it to make the tags not required. This means they shoul ...

Navigate Formik Fields on a Map

Material UI text-fields are being used and validated with Formik. I am looking for a way to map items to avoid repetitive typing, but encountering difficulties in doing so. return ( <div> <Formik initialValues={{ email: '&a ...

A guide to effectively validating a masked input field with material-ui, formik, yup, and react-input-mask

My current issue involves validating input using formik, yup, material-ui, and react-input-mask. When trying to use min/max length in the validationSchema, I am facing some challenges. The .required option works correctly, but when setting a mask for the i ...

Formik QR code reader button that triggers its own submission

I recently developed a custom QR code reader feature as a button within the Formik component customTextInput.tsx, but I encountered an issue where clicking on the button would trigger a submission without any value present. The following code snippet show ...

utilize console.log within the <ErrorMessage> element

Typically, this is the way the <ErrorMessage> tag from Formik is utilized: <ErrorMessage name="email" render={(msg) => ( <Text style={styles.errorText}> ...

Combining Material UI's Text Field with Formik Form using personalized components

Hello, I am currently utilizing the FORMIK form in my project and have integrated a few custom components such as a text field and select component. Now, I am looking to incorporate a date and time picker into the form using the Material UI library. Here i ...

Navigating the onSubmit with Formik in React: Tips and Tricks

I have a query regarding my usage of Formik in my React application. Within the onSubmit function, I am making an API call to a service. If this call fails, I want to immediately stop the rest of the submission process without executing any further action ...

Formik-powered button group for decreasing/increasing

Looking to enhance a Formik form framework by integrating a decrementer/incrementer button group. Link to Button Group Demo Button group codebase: import React from "react"; import Button from "@material-ui/core/Button"; import Button ...

Unable to modify background color when Material UI Toggle Button is selected

I'm working on implementing the Material UI Toggle Button as a radio button to present 2 choices for a question to the user. Most aspects of it are functioning as expected, but I am facing an issue when trying to customize the style for the selected ...

Learn how to implement icons within Textfield components using Material-UI and TypeScript in React

I have successfully created a form with validation using TypeScript Material UI and Formik. Now, I am looking to enhance the visual appeal by adding a material UI Icon within the textfield area. Below is a snippet of my code: import React from 'reac ...

React Checkbox Tree implemented with the Material-UI and Formik libraries. Elevate your ReactJS development with this

Trying to implement a Checkbox tree using Material-UIs Tree with formik for the form (checkboxes). I'm close to achieving it, but facing an issue where clicking on a parent node checkbox should also check its children nodes. Any suggestions on how to ...

Dynamic nested object in Formik

Can you provide a solution for the following scenario: For example, we have a checkout form with multiple delivery options, each requiring different details: In-store - requires only storeId Delivery office - requires cityId and officeId Courier - requir ...

I'm puzzled as to why I keep receiving the warning message about a component changing a controlled input to an uncontrolled one when I submit a form with Formik

Upon submitting a form using Formik, I encountered a warning that says: "A component is changing a controlled input to be uncontrolled. This issue usually arises when the value changes from a defined to undefined, which should not occur. It's importan ...

Build a flexible Yup validation schema using JSON data

I am currently utilizing the power of Yup in conjunction with Formik within my react form setup. The fields within the form are dynamic, meaning their validations need to be dynamic as well. export const formData = [ { id: "name", label: "Full n ...

What is the best way to incorporate NextJS routes in React while utilizing a form?

This is the main code section for my app const App = () => { const classes = useStyles(); const formik = useFormik({ initialValues: { name: "", email: "", password: "", confirmPassword: "" }, validationSc ...

Formik unable to access name prop in Material-UI slider component

Currently, I am in the process of building an application using react, formik, and material-ui. The challenge I am facing is trying to incorporate a slider into this project. It seems that the material-ui slider component does not expose the name prop to f ...

Trouble with validation in a react autocomplete feature for multiple selections when integrating with Formik

I'm currently working on validating an autocomplete multiple select using Formik. It initially works when a button is clicked, but I've noticed that if the selected value is removed, the validation doesn't trigger. import React from &quo ...

Checking the formik field with an array of objects through Yup for validation

Here is a snippet of the code I'm working on: https://codesandbox.io/s/busy-bose-4qhoh?file=/src/App.tsx I am currently in the process of creating a form that will accept an array of objects called Criterion, which are of a specific type: export inte ...

Tips for effectively utilizing Formik's handleChange method multiple times to update a single value

Utilizing Material-UI along with Formik, I am trying to enable two input fields to modify a single value. The scenario involves having a TextField and a Slider where both inputs should have the ability to change the value for period. When assigning the sam ...

Is it possible to include personalized validations in Formik's YupValidationSchema?

Is it possible to include custom validations in Formik's YupValidationSchema as shown below? YupValidationSchema = () => { return Yup.object({ Email: Yup.string() .max(256, "Length exceed 256 chars") ...

Changes trigger the re-rendering of inputs

My modal is causing all inputs to be re-rendered with every change I make while typing. I have a Formik object set up like this: const formik = useFormik({ enableReinitialize: true, initialValues: { sp_id: data?.id, ...

Implementing the useFormik hook for user authentication

Is anyone familiar with the useFormik hook? I am trying to validate a username and password on the server using the handleLogin(username, password) method. This is the code snippet I am currently working with: const LoginForm = withFormik({ mapPropsToV ...

Display the Material UI Switch in an active state even when the "checked" value is set to false

While using Material UI Switches with Formik, I've encountered an issue. When I toggle the switch to 'enable,' it automatically sets the value in Formik to "true," and when I toggle it to 'disable,' it sets the value in Formik to " ...

What is the solution for fixing the Typescript error in formik onSubmit?

I encountered an error while using the onSubmit prop of Formik: The type '(values: { email: string; password: string; }) => { type: string; payload: { email: string | null; password: string | null; }; }' is not compatible with the type '(( ...

Acquire Formik Validation for the Current Year and Beyond

How can I ensure that the input in Formik is restricted to the currentYear and later years only? const currentYear = new Date().getFullYear(); expiryYear: yup .string() .required('Please select an expiry year') .min(4, `Year format must be grea ...

Switch to copy values from one field to another in Formik

Hey there! I'm currently working on a form using Formik within NextJS and I have integrated a switch to allow users the option of using their contact details for invoicing purposes. While I have separate fields for both contact details and invoice de ...

I never receive back the funds I deposit into Formic

I am facing an issue with Formic where the value I store does not return to me as expected. The problem arises when the filter finds a specific value and logs it in line 57, then places the same value in Formic on line 58. However, when I log the Formic ...

Deselect the MUI Multi select option that was originally selected

Encountering an issue with MUI Select (multiple) within a Formik form. Let's say there is a task stored in the database with properties taskName and assignTo (an array of staff). The aim is to create a form where the assignTo values can be updated/cha ...

Most effective method for transferring data to linked selection fields across multiple components

I apologize for the recent influx of questions, but our volunteer mission is scheduled for December and I have a lot to accomplish. These initial inquiries will assist me in completing the remaining tasks! At this point, I am seeking the most effective me ...

Form fields do not pass validation when accessed via mobile devices

ISSUE: Successful form validation and async requests on desktop, but not functioning properly on mobile devices. TECHNOLOGY USED: Implemented nextjs, formik, and yup for the solution. DESCRIPTION: Developed a user-friendly form submission site that oper ...

The type '{} is not compatible with the type 'IProps'

In my current project, I am utilizing React alongside Formik and TypeScript. The code snippet below demonstrates my usage of the withFormik Higher Order Component (HOC) in my forms: import React from 'react'; // Libraries import........ import { ...

When Formik is used with React, the data value in a Material UI form is not cleared

After submitting the form data, I am utilizing formik.resetForm() to clear values from text fields. ... const handleSubmitProduct = async (values: Object, resetForm: any) => { ... code for processing form data ... resetForm() if (respon ...

Uploading files with the help of Formik and the Material-UI stepper component

When attempting to upload a file, the entire component refreshes each time. The process involves 3 steps: the first step captures the user's name, the second step collects their address, and the third step allows them to upload a profile picture. Howe ...

Upon modifying the selection, I am notified to utilize the 'defaultValue' or 'value' props on the <select> tag, rather than applying 'selected' on the <option> tag

I am currently working with a material select component: <FormControl fullWidth variant="outlined" className={classes.formControl}> <InputLabel ref={inputLabel} htmlFor="outlined-age-native-simple"> Filial </InputLabel> <Sel ...

Building a Switch component using Formik

Looking to integrate Formik with a Switch component that utilizes the design of a tooltip from the antd library. The basic implementation code resembles this: import React from 'react'; import 'antd/dist/antd.css'; import './i ...

Setting Default Value for Autocomplete in React

I'm facing an issue with the default value in my autocomplete feature within my React app. Even though I set a default value, when I try to submit the form, it still shows as invalid because it appears to have no value until I manually click on the au ...

What is the standard procedure for verifying the authenticity of a value?

Currently, I am working on a social media application that requires users to create unique usernames. Technology Stack The technology stack consists of Next.js, Prisma, and MySQL (hosted by Planetscale). Within the application, Formik and Yup are used fo ...

Formik state is mysteriously reverting field values to their default state

I've encountered an issue with my form and song state while trying to add a new field called "appleMusicId". Unfortunately, every time I add this field, it seems to reset the values of timeDescription and sceneDescription. I've spent hours tryin ...

Is it recommended to use Formik alongside the antd4 Form Component?

It seems that Formik and antd Form both offer similar functionalities: 1. validation 2. data-binding 3. error messages Find more information about Formik here Explore antd Form's features here Are their functions identical? ...

Unable to properly label or identify the DatePicker component for Yup validation

I've encountered an issue with my Formik form that utilizes Yup for validation. I'm having trouble integrating a Datepicker field into the yup validation process. Here's the code where everything renders correctly, but when I try to nest &l ...

Formik and Yup: The Perfect Pair

I have a form that includes a select input for choosing a country and a text input field that requires validation based on the selected country's EU tax regex. I am attempting to use yup for this task, but I am unsure how to retrieve the value of ano ...

Advice on utilizing setError with FieldArray?

In my code, I have an initial values list saved as an array: initialValues ={ ranges: [{ fromDate: '', endDate: '' }, { fromDate: '', endDate: '' }, { fromDate: '', endDate: &apos ...

Validating optional fields in Yup is a crucial step in ensuring that your form

What is the best way to validate an optional field that must not include special characters such as #<`> and a white space before a dot (.)? I have created a regex pattern \`|\#|\&|\<|\ \.|\> for this purp ...

What is the process to bring in a yup schema from a separate file?

In an effort to organize my form code more efficiently, I've been working on putting schemas in separate files. However, I've run into a issue where when I export a yup schema and then import it into another schema, the validation doesn't se ...

How can one conditionally validate that at least one of n values is set?

Is there a way to utilize Yup validation so that a field becomes mandatory if at least one of three other fields is not empty? I attempted the schema below but encountered a cyclic dependency issue. Any help would be greatly appreciated! const schema = ...

Creating beautiful forms with Material-UI and Formik

I am eager to incorporate Formik with MUI, but I am struggling to find a straightforward way to do so. The documentation is confusing and the examples provided are not very helpful. For instance, on this page, which is one of Formik's top-level examp ...

Issue with Yup and Formik not validating checkboxes as expected

I'm struggling to figure out why the validation isn't functioning as expected: export default function Check() { const label = { inputProps: { "aria-label": "termsOfService" } }; const formSchema = yup.object().shape({ ...

How to retrieve the value of input in a Formik form when the onChange event occurs

Currently, I am working on creating a form using React JS and the Formik library. One issue I encountered was related to validation, specifically the need to replace invalid letters with an empty string. str.replace(/\D/, ''); The challenge ...

Formik's handleChange function is causing an error stating "TypeError: null is not an object (evaluating '_a.type')" specifically when used in conjunction with the onChange event in DateInput

When using the handleChange function from Formik with the DateInput component in "semantic-ui-calendar-react", I encountered an error upon selecting a date. https://i.stack.imgur.com/l56hP.jpg shows the console output related to the error. AddWishlistFor ...

Issue with Formik Field failing to execute onChange event

My Formik field is displayed below. I am trying to trigger the onChange (or onKeyUp) event to execute some operation. Despite attempting solutions from previous questions on the same issue, nothing seems to be working for me so far. Can you please help i ...

Having trouble validating array length with Yup (using Formik and React)

Just joined Yup and struggling to validate an array that is not empty. My tech stack includes react, formik, yup, and material-ui. Here's a sample I put together: Check out the example here I attempted to use the required method in validationSchem ...

What is the best way to trigger the OnChange function in React when using Formik and Ant Design components together?

Is there a way to call a custom function on a Formik field when using the onChange event? I've tried calling it but it's not working as expected. Below is my custom function within a React Component: onStudentScore = (value, form) => { ale ...

Implementing dynamic value changes in MUI Select using Formik's onChange event

Integrating the Formik with the Select component of MUI presented me with a few obstacles. Initially, it failed to update the value on the onChange event and did not display any error messages when nothing was selected. After some troubleshooting, I was ...

Validate a field in a Formik form using React JS

Currently, I am utilizing Formik along with Yup for a project that is in progress. I am in the process of creating a multi-step form. The goal is to display the second step inputs when the user clicks on the next button, only if the inputs from step 1 are ...

The onSubmit function in Formik fails to execute if there are no input values present

I am currently working on building a form using Next.js, TypeScript, and the Formik + Yup libraries. I've encountered two scenarios: one where an input field is visible and Formik captures the value, and another where the input is not visible and the ...

Refresh the React query even if the key is already present in the cache

I recently developed a form using a combination of technologies including react, react-query, material ui, formik, and yup for schema validation. Check out the code here Custom fields I created: SelectField AutocompleteField CacheAutocompleteFie ...

formik does not support using the "new Date" function as an initial value

I have been trying to set the initial value of a date in my component like this, but when it renders I am encountering an error. const formik = useFormik ({ initialValues: { dob: new Date () } }) During this process, I'm facing the follow ...

Having difficulty updating the value of a FieldArray with setFieldValue in Formik

Thank you for taking the time to read this. I am currently working on creating a form using Formik that involves nesting a FieldArray within another FieldArray. Oddly enough, setFieldValue seems to be functioning correctly as I can log the correct values ...

Nested validation schema featuring conditional validation - yes, we've got it covered!

In my Formik object, I have set initial values as follows: {customerDetails: {id: "", name: "", mobileNumber: ""}, notes: {id: "", text: "", type: ""}} How can I create a conditional Yup validati ...

Verification of unique custom string

How can I ensure that a string follows the specific format of x.xx.xxxxx? The first character is mandatory, followed by a period, then two characters, another period, and finally any number of characters of varying lengths. ...

Having issues with validating a form using Yup for a Checkbox input?

My form is built using mui, formik, and yup. If the input fields are empty (e.g. "surname") after clicking the submit button, an error is displayed. However, the issue arises when the checkbox for Terms of Service isn't checked as no error shows up. ...

Tips on how to show a personalized <Errormessage> within a Formik field component while turning off the standard message

In my current web project, I am utilizing a combination of React, Material-UI, Formik, and formik-material-ui. Specifically, I have implemented a Formik form that includes validation using yup. const schema = yup.object({ name: yup.string().trim().low ...

Formik's validation feature does not currently support integration with Material UI's Autocomplete component

I am looking to showcase how validation errors are displayed when a user clears their selection. https://i.stack.imgur.com/ULEgs.png For reference, here is the sandbox link: https://codesandbox.io/p/sandbox/formik-autocomplete-yh3sl7?file=%2Fsrc%2FApp.ts ...

Using Ant Design with Formik to dynamically set field values in a form

When I click the "Change" button in an Antd table with data, the entire line of data is passed to a function as an object. However, I am having trouble inserting the data into the fields. What should I do? How can I set data to Antd input using an externa ...

Repeated Mistakes in Formik/Yup Validation Process

I have implemented the validation schema below using Formik: validationSchema = { Yup.object({ emails: Yup.array() .of(Yup.string().email('Ensure to enter valid email addresses only.')) .min(1, 'Please ...

Fill out a React formik form with the data that is already in place

Seeking guidance on how to manipulate or repopulate an existing form in React with backend data. I am using Formik and Formik Grid along with Axios for data retrieval. My goal is to edit a specific item in the inventory by updating its values from the da ...

Conditionally validate fields based on a different field using Yup and Formik

I am facing an issue with validation. I would like to set a rule that allows selecting both the start_date and end_date only if the access value is 1. Otherwise, if the access value is not 1, then only today's date should be selectable. Check out the ...

Saving the state to Redux within the handleSubmit function of a Formik React form

After submitting a Formik react form, I need to retrieve data via Ajax and set it as a variable in the redux store import React from 'react'; import {connect} from 'react-redux'; import { withFormik, Form, Field } from 'formik&apo ...