I have this schema:
const YupSchema = (t: TFunction) =>
Yup.object().shape({
name: Yup.string()
.required('*')
.max(49, 'maxСharacters' + ' 50'),
areas: Yup.array().required('*'),
activities: Yup.array().of(
Yup.object().shape({
id: Yup.string().required('*'),
pictureGood: Yup.string().required(
'Required'
),
pictureBad: Yup.string().required(
'Required'
),
translations: Yup.array() /* <=== hear I need get only first element in array*/
.of(
Yup.object().shape({
name: Yup.string().required('*'),
desc: Yup.string()
.required('*')
.max(999, 'maxСharacters' + ' 1000'),
locale: Yup.string()
.required('*')
.max(999, 'maxСharacters' + ' 1000')
})
)
.required('Translations Required')
})
)
})
For this data object:
[{"id":"","activitiId":"1","pictureGood":[],"pictures":[],"translations":[{"generalDesc":"test","descGood":"test","descBad":"test","locale":"IT"},"generalDesc":"test","descGood":"test","descBad":"test","locale":"EN"}]}]
But I need to validate only the first element in the array, not all. something like this: .
...
translations: Yup.array()[0]
.of(
Yup.object().shape({
name: Yup.string().required('*'),
...
Thanks for the answers!