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

customFields validate function should include parent reference #2408

Closed
mschipperheyn opened this issue Sep 22, 2023 · 2 comments
Closed

customFields validate function should include parent reference #2408

mschipperheyn opened this issue Sep 22, 2023 · 2 comments

Comments

@mschipperheyn
Copy link
Collaborator

Is your feature request related to a problem? Please describe.

A custom field can have a validate function which contains the current value plus an injector. However, what it's missing is a reference to the parent model instance.

E.g. I added originalPrice to a product variant. This allows me to show a non coupon related discount. This value should be higher than the current price and if it's not, and I don't account for negative discounts in the front end, I will get exactly that, a negative discount.

Describe the solution you'd like

IMHO, a parent reference would help in many cases to implement common validation scenario's. It would be a reference to the instance of the model that the form is for that the custom field is on.

Describe alternatives you've considered
Fix it in the frontend. This is more of a workaround, bc the data in this scenario is already bad.
I guess you can write a plugin to deal with this scenario

Additional context

@mschipperheyn
Copy link
Collaborator Author

It should in fact also contain an object tree representing the entire filled out form, as the parent could be undefined if you're creating a new item

@michaelbromley
Copy link
Member

I think the most workable solution to this would be to pass the RequestContext ctx object into the function. From that, you can get the Express req object and inspect the current operation to find the variables passed in to the current GraphQL mutation.

@michaelbromley michaelbromley moved this to 📅 Planned in Vendure OS Roadmap Nov 14, 2023
@michaelbromley michaelbromley moved this from 📅 Planned to 🏗 In progress in Vendure OS Roadmap Jan 25, 2024
@michaelbromley michaelbromley moved this from 🏗 In progress to 🔖 Ready in Vendure OS Roadmap Jan 25, 2024
@michaelbromley michaelbromley moved this from 🔖 Ready to ✅ Done in Vendure OS Roadmap Apr 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: 🚀 Shipped
Development

No branches or pull requests

2 participants