fix: give fields a user-friendly label

This commit is contained in:
siiky 2024-09-02 15:24:22 +01:00
parent fc47944ac8
commit f1566c1bcc
4 changed files with 31 additions and 11 deletions

View file

@ -65,7 +65,9 @@ const ChooseType = () => {
}
const validationSchema = Yup.object().shape({
inputType: Yup.string().required()
inputType: Yup.string()
.label('Input type')
.required()
})
const defaultValues = {

View file

@ -32,8 +32,12 @@ const Screen1Information = () => {
}
const validationSchema = Yup.object().shape({
screen1Title: Yup.string().required(),
screen1Text: Yup.string().required()
screen1Title: Yup.string()
.label('Screen title')
.required(),
screen1Text: Yup.string()
.label('Screen text')
.required()
})
const defaultValues = {

View file

@ -30,8 +30,12 @@ const ScreenInformation = () => {
}
const validationSchema = Yup.object().shape({
screen2Title: Yup.string().required(),
screen2Text: Yup.string().required()
screen2Title: Yup.string()
.label('Screen title')
.required(),
screen2Text: Yup.string()
.label('Screen text')
.required()
})
const defaultValues = {

View file

@ -40,28 +40,38 @@ const validationSchema = Yup.lazy(values => {
switch (values.inputType) {
case 'numerical':
return Yup.object({
constraintType: Yup.string().required(),
constraintType: Yup.string()
.label('Constraint type')
.required(),
inputLength: Yup.number().when('constraintType', {
is: 'length',
then: Yup.number()
.min(0)
.required(),
.required('The number of digits is required'),
else: Yup.mixed().notRequired()
})
})
case 'text':
return Yup.object({
constraintType: Yup.string().required(),
inputLabel1: Yup.string().required(),
constraintType: Yup.string()
.label('Constraint type')
.required(),
inputLabel1: Yup.string()
.label('Text entry label')
.required(),
inputLabel2: Yup.string().when('constraintType', {
is: 'spaceSeparation',
then: Yup.string().required(),
then: Yup.string()
.label('Second word label')
.required(),
else: Yup.mixed().notRequired()
})
})
case 'choiceList':
return Yup.object({
constraintType: Yup.string().required(),
constraintType: Yup.string()
.label('Constraint type')
.required(),
listChoices: Yup.array().test(
'has-2-or-more',
'Choice list needs to have two or more non empty fields',