A
A
Anastasia Panfilova2018-12-19 22:37:18
React
Anastasia Panfilova, 2018-12-19 22:37:18

Is it possible to "build" a yup validation schema?

The bottom line is that I receive form fields and conditions for their validation from the server.
Is it possible to assemble a validation scheme depending on the yup conditions, for example, in this way:

let s = Yup.string()
            if (current.minimum && current.minimum !== '0') {
              s.concat(Yup.string().min(Number(current.minimum)))
            }
            if (current.maximum) {
              s.concat(Yup.string().max(Number(current.maximum)))
            }
            if (current.required === 'required') {
              s.concat(Yup.string().required('!!'))
            }

there is a cycle, and thus each field is checked (current)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question