ng2-validation icon indicating copy to clipboard operation
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

Open shahmirn opened this issue 7 years ago • 3 comments

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

shahmirn avatar Feb 28 '17 16:02 shahmirn

@yuyang041060120 please take a look

shahmirn avatar Feb 28 '17 16:02 shahmirn

@shahmirn You did not have to the problem I described in https://github.com/yuyang041060120/ng2-validation/issues/59?

Chuvisco88 avatar Mar 03 '17 07:03 Chuvisco88

@Chuvisco88 I didn't

shahmirn avatar Mar 06 '17 15:03 shahmirn