-
Notifications
You must be signed in to change notification settings - Fork 6
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
In FluentValidation it is possible to string together multiple when statements for a single property. In this library the behaviour does not work as expected. For example:
this.ruleFor("days")
.notEmpty()
.must([beNumeric, beAnInteger, beGreaterThanOrEqualTo(0)])
.withMessage("days must be greater than or equal to 0")
.must([beNumeric, beAnInteger, beLessThan(2000000000)])
.withMessage("The maximum allowed number size is 1,999,999,999")
.must((value, model) => asNumber(value) > 0 || asNumber(model.otherDays) > 0)
.withMessage("days and otherDays cannot both be 0")
.when((model) => model.dayCode== "weekday")
.null()
.withMessage("days must not be entered for weekendDays")
.when((model) => model.dayCode!= "weekendDay");
Is not the same as:
this.ruleFor("days")
.notEmpty()
.must([beNumeric, beAnInteger, beGreaterThanOrEqualTo(0)])
.withMessage("days must be greater than or equal to 0")
.must([beNumeric, beAnInteger, beLessThan(2000000000)])
.withMessage("The maximum allowed number size is 1,999,999,999")
.must((value, model) => asNumber(value) > 0 || asNumber(model.otherDays) > 0)
.withMessage("days and otherDays cannot both be 0")
.when((model) => model.dayCode== "weekday");
this.ruleFor("days")
.null()
.withMessage("days must not be entered for weekendDays")
.when((model) => model.dayCode!= "weekendDay");
The second set of code provides the expected behaviour.
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working