Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[v4] Support reactive form validation schema #3235

Closed
ahoiroman opened this issue Mar 27, 2021 · 4 comments · Fixed by #3238
Closed

[v4] Support reactive form validation schema #3235

ahoiroman opened this issue Mar 27, 2021 · 4 comments · Fixed by #3238
Labels
✨ enhancement a "nice to have" feature 🛳 In PR This issue is being addressed in a PR

Comments

@ahoiroman
Copy link

Versions

  • vee-validate: 4.2.4
  • vue: 3

Describe the bug

I'd like to include an reactive array to a oneOf/notOneOf check using Yup:

 data: () => ({
        field: {
            options: []
        },
    }),
    computed: {
        schema () {
            return Yup.object ({
                field: Yup.object ().shape ({
		    newOption: Yup.string ().max(255).notOneOf(this.field.options).required ()
                })
            });
        },
    },
   methods: {
     addOption(option) {
         this.field.options.push (option)
     }
  }
 },

As you may see, the field.options can be filled by a function call. But unfortunately the schema does not update if a new option is added. If I do something like:

data: () => ({
        field: {
            options: ['test']
        },
    }),

the rule works and I can not add the string "test".

@logaretm
Copy link
Owner

I don't think it's possible, yup is a 3rd party library and while vee-validate has first-class support for it, I can't really do anything about this.

I'm not sure if yup clones the arrays when initializing the schema or not, but like I said if it doesn't work then there isn't much I can do about it.

The only possible workaround is for vee-validate to add reactive schema support which basically allows you to create computed schema objects, but I will need to experiment with this more as there are few issues to iron out with this idea.

I will tag this as an enhancement while I experiment with it. Thanks for bringing this up.

@logaretm logaretm added the ✨ enhancement a "nice to have" feature label Mar 28, 2021
@logaretm logaretm changed the title Pass reactive elements to yup-schema (oneOf/notOneOf) [v4] Support reactive form validation schema Mar 28, 2021
@ahoiroman
Copy link
Author

Alright. As I would benefit from this feature, I am wondering if I can sponsor such a feature. The sponsor-button in this repo does not work:

Sponsor logaretm/vee-validate
The FUNDING.yml file does not currently contain valid funding links.

@logaretm
Copy link
Owner

Thank you, I appreciate the sentiment. Sadly there isn't a good way to get money here in Egypt or getting sponsored via GitHub at the moment. Maybe one day 😞

Don't worry about it, I see this as a useful feature so I will work on it on the upcoming few days

@logaretm logaretm added the 🛳 In PR This issue is being addressed in a PR label Mar 28, 2021
@ahoiroman
Copy link
Author

Works fine. Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨ enhancement a "nice to have" feature 🛳 In PR This issue is being addressed in a PR
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants