yuyang041060120 / ng2-validation

angular2 validation
https://yuyang041060120.github.io/ng2-validation/index.html
MIT License
613 stars 214 forks source link

min and max validators should ignore date values instead of trying to typecast them into numbers and getting NaN, causing validation to fail #58

Open shahmirn opened 7 years ago

shahmirn commented 7 years ago

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 commented 7 years ago

@yuyang041060120 please take a look

Chuvisco88 commented 7 years ago

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

shahmirn commented 7 years ago

@Chuvisco88 I didn't