[QUESTION] Conditional validation in Model
See original GitHub issueHello!
Does Ts.ED provide a way to perform a conditional validation of a model based on another field in the model? Consider the following example
export enum Buyer {
Person = "PERSON",
Company = "COMPANY"
}
export class Invoice {
@Required()
@Enum(Buyer)
buyer: Buyer;
@Optional()
// I'd like this field to be required only if buyer === 'COMPANY'
companyData?: CompanyData
@Optional()
// ... and this field should be required only if buyer === 'PERSON'
// something like:
// @RequiredIf(o => o.buyer === 'PERSON')
personData?: PersonData
}
For the record, it doesn’t really matter for me if this requirement is reflected in JSON Schema (both fields can be optional), I’m only caring about validation of request.
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (1 by maintainers)
Top Results From Across the Web
ASP.NET MVC Conditional validation - Stack Overflow
I would like to be the "Senior. Description" property conditional required field based on the selection of the "IsSenior" propery (true -> ...
Read more >Conditional Validation -- Help Manual - Survey2Connect
Conditional Validation logic helps you validate the data that you have enter in a textbox question by creating an equation.
Read more >DotVVM - Build Conditional Validation Attribute - C# Corner
You can validate your view model by using validation attributes. DotVVM does client side validation for only the following attributes:.
Read more >RequireIf conditional validation in MVC - MSDN - Microsoft
User-730945238 posted. In my model I have the below property. public int? Data { get; set; } and using `@Html.TextBoxFor(m => m.
Read more >Conditional ASP.NET MVC Validation using Data Annotation ...
In projects, there will be cases when you need to have conditional validation depending on the action method or even the data.
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 Free
Top 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
I decided to just extend
JsonSchemaObject
like this:No more complains 😃
I close this issue. This feature will be implemented with #1336