Questions tagged [yup]

Yup is a JavaScript object schema validator and object parser based on Joi

Yup is a JavaScript object schema validator and object parser. The API and style is inspired by Joi.

Yup is leaner than Joi: in the same spirit, without some of the fancy features. You can use it on the server as well, but in that case you might as well just use Joi.

Yup is also a good bit less opinionated than joi, allowing for custom transformations and async validation. It also allows "stacking" conditions via when for properties that depend on more than one other sibling or child property. Yup separates the parsing and validating functions into separate steps so it can be used to parse json separate from validating it, via the cast method.

Documentation and source can be found on the yup github page

1580 questions
0
votes
1 answer

Yup Multi Conditional validation

I have 3 fields that are not required by default. However, the rule demands that if any of the 3 fields is provided then all 3 will be required. Example field_1, field_2 & field_3 validataionSchema = Yup.object({ title: Yup.string().max(10, "Max…
Paullo
  • 2,038
  • 4
  • 25
  • 50
0
votes
1 answer

Cast only what is defined in the schema and strip out extra fields - Yup

I have this schema: yup.object().shape({ name_first: yup.string().required().label("Name First").meta({ initial: "" }), name_last: yup.string().required().label("Name Last").meta({ initial: "" }), mobile: yup .number() …
Sami Al-Subhi
  • 4,406
  • 9
  • 39
  • 66
0
votes
2 answers

How to set formik values

index.js const [request, setRequest] = useState({ product_name: '', categoryId: '', description: '', link: '' }); const loadRequest = async () => { const res = await Axios.get(`http://localhost:3001/dashboard/${id}`, { …
Shubham Sharma
  • 321
  • 1
  • 6
  • 18
0
votes
1 answer

how to validate "input type = 'date' " with Formik and Yup

I am starting in React and now I have the challenge of form validation and for this, looking for ways to work with the validations I found the Formik and Yup libraries But it turns out that there is no example of how to validate an "input type =…
KelvinLB
  • 3
  • 1
  • 2
0
votes
1 answer

React, Formik, Yup: How to format the phone input

I'm new to React and I have done a multistep form for signing up using React bootstrap, Formik, and validation with Yup. I want to add functionality that will allow me to format (or mask) user inputs in a couple of fields. While user typing, I want…
Sereban
  • 13
  • 1
  • 4
0
votes
1 answer

How to resolve issue with mutiple field name unknown . Use yup and reactjs

I have array field name ... unknown field name , array field name get from database. They is same validation .How to validation with yup unknown field name ? const schema=yup.object().schema({ nameField1:yup.required('required') .min(5,…
TienDev
  • 5
  • 1
0
votes
1 answer

Formik + Yup date required validation

I am trying to use Formik with Yup & material-ui/pickers. Whenever I try to make a date field required this never shows an error message. upon console logging out the Formik Errors I see that it loops through logging the error then resetting it to a…
0
votes
1 answer

Yup validation schema object conditional validation

I want to baisically say if type = 1 then validate the membership object , did try it with .when() but had to do it with eacth of the object (only when type =1 then validate validationSchema={Yup.object().shape({ //General …
0
votes
1 answer

Validate fields conditionally based on another field in Yup and Formik

I have a problem in validation. I wanted that if access value is 1 then you can select the start_date and end_date BUT if the value of access is not 1, then you can only select today. Codesandbox export const validationSchema =…
Joseph
  • 7,042
  • 23
  • 83
  • 181
0
votes
1 answer

Conditional validation for fields based on select option - yup

So while learning, forms i found this package - yup for validating. But i am getting a problem So i will explain the problem statement and what i have tried so far. So the use case is i have a select field, which has two options, Resident and…
dev
  • 814
  • 10
  • 27
0
votes
1 answer

Yup: Ensure at least one of the elements in an array is valid

I have the following schema: const baseSchema = { name: Yup.array().of( Yup.object().shape({ lang: Yup.string().required(), value: Yup.string() .min(2) .max(20) .required() }) ) }; Is there a way to…
tdranv
  • 1,140
  • 11
  • 38
0
votes
1 answer

Show validation when user selects specific radio button

I have two radio buttons (yes/no) in React.js with Formik and Yup packages used in my projects. I want to provide a validation message using schema when the user selects the NO option out of the two. I am able to provide the required validator with…
aarti
  • 175
  • 2
  • 15
0
votes
3 answers

React Semantic Date Picker disable select past dates

I'm using react-semantic-ui-datepickers to select a date into a form, also using Formik and Yup for validation. Is there a way to disable the past dates so the user can only choose a date starting from today? This is the code: import React from…
Leo Messi
  • 5,157
  • 14
  • 63
  • 125
0
votes
1 answer

Get the value from input of Formik's Field

There is a Formik field for validating some data, it looks like this: this.handleDelete(values)}> {({ values, errors, touched,…
Leo Messi
  • 5,157
  • 14
  • 63
  • 125
0
votes
1 answer

React formik validationSchema conditionalValidation

Basicaly all I want to do is say is if region = "Europe" or "other" then the field is required , did go through the formik documentation but not finding anything. Am also new to formik so dont know if this is a nube question or not Did try an array…
ChrisJnr Potgieter
  • 141
  • 1
  • 2
  • 13