Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

shahmirn
Copy link
Contributor

@shahmirn shahmirn commented Feb 28, 2017

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

…/HTML/Element/input, min and max can take a date-time value.

When that happens, these two validators ends 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
Copy link
Contributor Author

@yuyang041060120 please take a look

@Chuvisco88
Copy link
Contributor

@shahmirn You did not have to the problem I described in #59?

@shahmirn
Copy link
Contributor Author

shahmirn commented Mar 6, 2017

@Chuvisco88 I didn't

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants