[FEATURE] Conditional Validation
See original GitHub issueSummary:
Would love if there was a way to run validation on an attribute if a different attribute is set to a specific value.
Code sample:
General
In a different package(https://github.com/clarkie/dynogels
) that i’m using, it uses Joi where I can do this…
age: Joi.when('application_id', { is: 'foo', then: Joi.string().trim().required(), })
So this attribute is only required if application_id
is set to foo
. Doesn’t necessarily have to use Joi, thats just what that other package uses.
Other:
- I have read through the Dynamoose documentation before posting this issue
- I have searched through the GitHub issues (including closed issues) and pull requests to ensure this feature has not already been suggested before
- I have filled out all fields above
- I am running the latest version of Dynamoose
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
feature: Conditional validation inside validation options #1721
Sometimes we need to validate a field based on another field in the dto. Proposed solution. it would be nice to have an...
Read more >A Guide to Using Conditional Data Validation | Excelchat
Conditional data validation means restricting the choices in an Excel drop-down list depending on the value in another cell (or in another drop...
Read more >3 ways to implement conditional validation of Angular reactive ...
We want clarity. Another way to achieve conditional validation in Angular forms would be to write your own group validator. This validator will...
Read more >Conditional Validation for Elementor Pro Form - Dynamic.ooo
This feature helps you validate your Elementor Pro forms with simple conditional expressions. This will help to ensure that the form is submitted...
Read more >Conditional validation | Drupal.org
Conditional validation is an available option to select after you choose a validator. As the name implies, if it is selected (and configured...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
So based on my last comment.
This is done, and will be included in the next v3 release (by the end of this weekend at the latest, if a new release hasn’t been released by the end of the weekend please remind me to do so).
Additionally (and kinda unrelated), there is support for
get
andset
modifiers on the schema settings itself.This is a function that the item object is passed into. It does not currently accept an array of functions. If someone believes having an array of functions would be valuable, please create a new feature request issue for this.
Sadly, I have no idea if this is going to make it into v3. It’s really hard to say at this point.
See above. This is even less likely at this point.
Example:
So the short version: This is now possible. But not quite as seamless as it would be if Dynamoose had a Joi plugin.
So I will be closing this issue.
Disclaimer: I still have not used Joi before. Would appreciate someone testing out this new functionality to see if they can get it working, and report back if it’s successful or if the API needs to be changed or can be improved to better fit Joi validation.
After thinking about this a bit more. This seems like it’d be a good plugin for Dynamoose. In v3 I’m planning to explore basic plugin support.
In v3 I will either develop a plugin to support Joi validation, or support Joi validation natively.
Might also be interesting to explore having a validate function on the schema itself. That way you can validate the entire item and ensure the entire item is what you expect.