ng2-validation
ng2-validation copied to clipboard
min and max validators should ignore date values instead of trying to typecast them into numbers and getting NaN, causing validation to fail
According to MDN at https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input, min and max can take a date-time value.
My use case is I have an input field with the HTML:
<input type="date"
id="calculationDate"
class="form-control"
name="calculationDate"
min="1900-01-01"
minDate="1900-01-01"
max="2099-12-31"
maxDate="2099-12-31"
[(ngModel)]="model.calculationDate"
#calculationDate="ngModel"
required
date/>
I use min and max so that when chrome displays its built-in calendar widget, dates before min and after max are grayed out / unselectable.
However, when I have this HTML, the min and max validators end up trying to convert these values into a number, which results in NaN, which causes the validation to fail.
To fix this issue, if the min or max value isNaN and is a date, then simply return null. The validtion of these fields are handled by minDate and maxDate
@yuyang041060120 please take a look
@shahmirn You did not have to the problem I described in https://github.com/yuyang041060120/ng2-validation/issues/59?
@Chuvisco88 I didn't