I have an array of nested objects in a Formik/React form:
variablePrice: [ { orderMin: 1, orderMax: 3, price: 20.00, }, { orderMin: 4, orderMax: 6, price: 18.00, }, { orderMin: 7, orderMax: 10, price: 16.00, }, ]
I am trying to use Yup to ensure that for any new object added in the Fieldarray the orderMin of the next object is larger than the order max of the previous object in the FieldArray.
So far, i have :
variablePrice: Yup.array().of(
Yup.object().shape({
orderMin: Yup.number()
.required("orderMin Value is required")
.positive("orderMin Value can only be a positive number")
.min(0, "orderMin Value can not be a negative number"),
orderMax: Yup.number()
.required("orderMax Value is required")
.positive("orderMax Value can only be a positive number")
.moreThan(Yup.ref("orderMin"), "orderMax Value must be higher than the orderMin Value"),
price: Yup.number()
.required("Price is required")
.positive("price can only be a positive number")
.min(0.01, "Price must be above 0"),
})
)
Any suggestions are welcome. Thanks in advance.