Questions tagged [yup]

Yup stands as a commanding JavaScript tool, designed to validate and parse object schemas, borrowing its strength from the robust Joi framework.

Implementing conditional validation in Formik on cancel button click in a React application

When defocusing from the field without entering any data, a validation error occurs. Similarly, if you click on the submit button without giving a value, a validation error is triggered - this behavior is expected. However, how can we prevent the validat ...

The MUI Radio button group is unexpectedly outputting strings instead of boolean values, despite being passed the

Currently, I am in the process of developing a form using RHF V7 and MUI V5 while validating its data with yup. One major hurdle that I've encountered is related to a radio button group returning a string value of 'true' or 'false' even when being provided ...

What is the best way to activate yup validation in react-hook-form prior to the user clicking the submit button?

I am currently using react-hook-form along with yup validation and MUI components in my react TypeScript application. The issue I am facing is that the errors from the yup validation only appear after the user tries to submit the form by clicking on the su ...

Issue with react-hook-form integration with material ui file upload component resulting in missing FileList

Having an issue with React Hook Form and Material-UI file uploading. When submitting the form, I receive a string path of one file instead of FileList instance. <Controller name='attachments' control={control} defau ...

Using the Formik validation schema with Yup, determine whether the input is either "answer" or "another answer"

I'm trying to set up a form where if the region is "Europe" or "other", then certain fields are required. I've looked through the Formik documentation but haven't found a solution yet. <Formik enableReinitialize={true} initialValues={{ name: curre ...

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 autocom ...

Struggling to implement Yup Validation in MUI while using React Hook Form in a masked Controller field

I've hit a wall with React Hook Form phone masking and validation. Any assistance would be greatly appreciated! My setup involves using React Hook Form with Yup for form validation and MUI for UI. I managed to implement masking on my phone field usin ...

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 ...

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 Yu ...

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 <DatePicker/&g ...

Correct validation is not achieved when the "!" symbol is used in the matches function

I am working on a React and Next.js project where I am using Formik for handling forms and Yup for validations. One specific input field requires some validations to be performed. This field must be required, so if the user does not enter any information, ...

Tips for managing blur events to execute personalized logic within Formik

I am currently delving into the world of React/Next.js, Formik, and Yup. My goal is to make an API call to the database upon blurring out of an input field. This call will fetch some data, perform database-level validation, and populate the next input fiel ...

TextField from MUI isn't updating with react-hook-form, onChange event is not triggering

const [userInfo, setUserInfo] = useState({ fullName: "", email: "", }); // State for user information const handleChange = (event) => { console.log(event.target.value); }; // Function to handle input changes <Grid contain ...

Checking for Age Validity with Formik and Yup: How to Ensure a Date Represents Someone Who is Eighteen Years Old or Older

I'm currently working on a form using Formik, Yup, and ReactJS. Specifically, I am focusing on the date field validation to ensure that the user is at least 18 years old. Within the validationSchema parameter in Formik, I have included the following code: ...

Have you considered using a prepopulated value as the default value in Autocomplete Material UI using the controller of react-hook-form?

I've utilized the controller component from react-hook-form to trigger the material UI autocomplete feature successfully. However, when I include a defaultValue parameter and then click on the submit button, an error message appears indicating validation ...

MUI: (Autocomplete) The input given for Autocomplete is not valid

While attempting to load data into an MUI Autocomplete, I encountered this message in the console. React-hook-form and yup are being used for form validation. Image displaying the warning To showcase my issue, I have set up a CodeSandbox. In this example, ...

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 ...

Checking if a start date comes after an end date using Yup - how is it done?

How can I use Yup to validate if the start date overlaps with the end date in a form that creates an event using Formik library? I have two date pickers for choosing the dates and times. I want to display an error message if they overlap. Thanks for the ...

Utilizing Formik alongside Yup and React-select for enhanced validation

Currently, I am implementing form validation in a React project using both Yup and Formik. The challenge I am facing is with validating a react-select element within the form. To achieve this, I am utilizing the validationSchema property of Formik to valid ...

Having some issues with validating numbers in typescript

When implementing react hook form in my React app, I encountered an issue while validating specific fields and had to add some conditions to the schema. yup .object({ test1: yup.number().when('test2', (test2: number, schema: yup.NumberSchem ...

Formik is being utilized to transform an uncontrolled input into a controlled input within a component

While working with a form using Formik, Yup, and NextUi v2 Inputs, an issue arises when typing in one of the inputs that triggers a warning in the console: A component is changing an uncontrolled input to be controlled. This warning is usually due to the ...

Aligning validation schema with file type for synchronization

Below is the code snippet in question: type FormValues = { files: File[]; notify: string[]; }; const validationSchema = yup.object({ files: yup .array<File[]>() .of( yup .mixed<File>() .required() .t ...

What could be causing the issue with typing into the Formik and Yup input fields?

Whenever I attempt to enter text into the input fields, no characters show up. Strangely, a similar login page using the same code is functioning perfectly fine. At this moment, I'm baffled as to why it isn't working on this specific one. My suspicion wa ...

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 ...

Encountering issues post upgrading Material-ui from version 4 to 5 while utilizing a component with react-number-format

I recently updated my material-ui version from v4 to v5, but I'm encountering issues with a component that utilizes the react-number-format library. It seems like the problem is related to forwarding refs, and despite my efforts, I haven't been able to res ...

Required Field Validation - Ensuring a Field is Mandatory Based on Property Length Exceeding 0

When dealing with a form that includes lists of countries and provinces, there are specific rules to follow: The country field/select must be filled out (required). If a user selects a country that has provinces, an API call will fetch the list of provinc ...

Best Practices for Validating Form Inputs using react-final-form Across Multiple Screens

Using a combination of react-final-form, material ui, mui-rff, and yup for form validations presents some challenges when dealing with multiple wizard screens. Each screen contains HTML form elements such as inputs and radio buttons that are required for u ...

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({ ...

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 code ...

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 validationSchema: va ...

Assist with automatically updating a field value based on user input during React Hook Form validation

TL;DR To see the working code, visit: https://codesandbox.io/s/stoic-beaver-ucydi The refactored version using React Hook Form can be found here: https://codesandbox.io/s/objective-cloud-bkunr?file=/src/ControlledTextField.tsx In Depth Explanation No Re ...

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 ...

Validating numbers using the Formik and Yup libraries

Hey there, I'm currently facing an issue while using Formik + Yup to validate my form. I am having trouble validating the number for the date, and whenever I try to interact with any field, the app crashes after adding the number field. Can someone pr ...

What is the best way to incorporate an SVG icon into the helper text created by Formik and Yup within Material UI components?

With the React form in my setup, I am utilizing Formik, Yup, and Material UI for forms and textfields: import { TextField } from '@material-ui/core'; This is specifically for the E-mail form. Upon blurring out of the field, it produces the foll ...

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 ...

Is there a way to display an MUI TextField/FormControl error message with a distinctive left red border that only appears if there is an error present?

When the validation fails, my goal is for the error message and TextField to be styled like this: View Desired Result Image. Currently, with MUI, I've made progress towards the desired look. Here's where I'm at: View My Progress Image, but I'm unsure how ...

Passing a boolean value from Material UI Radio to utilize in Yup .when validation

Yup offers the ability to validate based on another value using .when. For example: var inst = yup.object({ isBig: yup.boolean(), count: yup .number() .when('isBig', { is: true, // alternatively: (val) => val === true then: yup ...

Validating image uploads using Yup and Formik in a standalone module

I am facing an issue in my Next.js application where I am attempting to validate the upload of an image using Formik and Yup by passing a method called handleOnImageChange in the component. However, I am struggling to make it work this way. I have also tri ...

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 ...

I'm curious why one of my Material UI autocomplete components is displaying options with a blue background while the other isn't. Take a look at the code sandbox for more insight

UPDATE: Problem solved! I managed to find a solution and have updated my sandbox with the fix! REVISION: After some investigation, I have identified that the issue lies within this specific line of code in the autocomplete... isOptionEqualToValue={(option ...

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 ...

Resetting the initial values in Formik while utilizing Yup validation alongside it

Currently, I am working on a React application with Typescript and using Formik along with Yup validation. However, I have encountered an issue with setting values in a Select element. It seems that the value is not changing at all, or it may be resettin ...