|
Nick, I've tested the new version and it still doesn't work for my case. But the good news is that it can be easily fixed.
The problem is that I need that when one of the properties (value or depedentValue) is null,
or when
both properties are null these validators let it pass. And I will explain why IMHO this is not only correct from the point of view of practicity (because with my proposed implementation we can handle the nulls in another validator and let alone
this one which just handle well known use cases), but also from logical the point of view:
Null usually means "undefined" or "not applicable", and should not be confused with "0" or some other defined/well-know comparable value. And so
undefined is not equal to undefined, we can not compare undefined because we don't know what it is. I believe that data annotations validators are made to mark user failures that are totally expected, and not unexpected
cases which are not really clear. That is why the RangeAttribute will not return false if the user leave the field black. If you want to filter nulls you don't touch the range validator, you just add the RequiredAttribute too.
These are the lines of code which are affected (they return true when only one of the values are null, but the validation continues (and fails) when both are):
C#: if (PassOnNull && (value == null || dependentValue == null) && (value != null || dependentValue != null))
JS: if ((value1nullish && !value2nullish) || (value2nullish && !value1nullish))
What I've done to fix my problems was just changing those lines to:
C#: if (PassOnNull && (value == null || dependentValue == null))
JS: if (value1nullish || value2nullish)
What do you think?
|