Skip to content

Can't define field names of dynamically added input fields in yup schema #3418

Answered by logaretm
ValentineSean asked this question in Q&A
Discussion options

You must be logged in to vote

This is a question and belongs to the discussion section, not an issue.

You can use a computed property to create a dynamic schema:

{
  computed: {
    schema() {
      // construct your schema here
      return yup.object(this.documents.reduce((schema, document) => {
        schema[document.id] = yup.mixed().required();
        
        return schema;
      }, {}));
    }
  }
}

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@ValentineSean
Comment options

Answer selected by ValentineSean
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #3416 on July 28, 2021 09:53.