Open MLNW opened 1 month ago
garde
applies all validations and aggregates all failures in one report. You're using length(graphemes)
, so it's correctly failing in the first test.
There is an issue open for a mode that would stop on the first failure #1
Your response makes sense. Would it be possible to include an option to treat surrounding whitespace as zero length in the length check? Then one wouldn't have to implement a custom validation for it.
Being able to stop early would also be appreciated.
Would it be possible to include an option to treat surrounding whitespace as zero length in the length check?
I think this is better handled either by rejecting the whitespace using client-side validation, or using a custom validator as you have done. garde
is not really intended for use cases where you need to modify the data in some way before validating it.
I just started using
garde
and hit a road block with thelength
validation. I want to ensure a string is neither too short nor too long. That is simple. Until whitespace is involved.This is my basic new type struct:
I have these two tests for the scenario:
The first test fails with:
Okay, the provided string does have a length within the specified range. So I implemented a custom validator:
Now the second test fails with:
It would be great if there was a way to explicitly handle white space in the length check or have one validation supersede another. In this case for example the string is blank so it should only report that right?