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

[minDate] and [maxDate] validation returns misleading error description #2922

Closed
03byron opened this issue Dec 12, 2018 · 1 comment · Fixed by #3607
Closed

[minDate] and [maxDate] validation returns misleading error description #2922

03byron opened this issue Dec 12, 2018 · 1 comment · Fixed by #3607

Comments

@03byron
Copy link
Contributor

03byron commented Dec 12, 2018

Bug description:

Current [minDate] and [maxDate] validation returns misleading error description.

E.g. When [minDate] is set to today and you enter yesterday, validate() returns:

{'ngbDate': {requiredBefore: this.minDate}}

but it should be

{'ngbDate': {requiredAfter: this.minDate}}

Same applies for [maxDate]. When maxDate is set to today and you enter tomorrow you get:

{'ngbDate': {requiredAfter: this.maxDate}}

but it should be

{'ngbDate': {requiredBefore: this.maxDate}}

@maxokorokov
Copy link
Member

maxokorokov commented Dec 12, 2018

Here is the stackblitz with the issue: https://stackblitz.com/edit/angular-snykrp.

date = 1 OCT 2018
minDate = 10 OCT 2018

I would expect the message to be along these lines:

  • error: ngbDate is before 10 OCT 2010
  • error: ngbDate must be after 10 OCT 2010

Currently it is:

  • error: ngbDate required before 10 OCT 2010
FC: {
  "ngbDate": {
    "requiredBefore": {
      "year": 2018,
      "month": 10,
      "day": 10
    }
  }
}

I'd prefer to change requiredBefore to isBefore, mustBeAfter or simply beforeMinDate.

I'll leave @pkozlowski-opensource decide. And it is a breaking change.

@maxokorokov maxokorokov modified the milestones: 4.0.1, 5.0.0 Dec 12, 2018
@benouat benouat modified the milestones: 5.0, 6.0 Jul 9, 2019
@maxokorokov maxokorokov self-assigned this Feb 14, 2020
maxokorokov added a commit to maxokorokov/ng-bootstrap that referenced this issue Feb 19, 2020
Fixes ng-bootstrap#2922

BREAKING CHANGE:

'ngbDate' validator error messages were changed to be more explicit and aligned with Angular validators.
For the following use-case `<ngb-datepicker [ngModel]="{year: 2019, month: 12, day: 31}" [minDate]="{year: 2020, month: 1, day: 1}"></ngb-datepicker>` form control errors are:

Before

```
ngbDate: {
  requiredBefore: { year: 2020, month: 1, day: 1 }
}
```

After

```
ngbDate: {
  minDate: {
    minDate: { year: 2020, month: 1, day: 1 },
    actual: { year: 2019, month: 12, day: 31 }
}
```

Same change is applied for `requiredAfter` and `maxDate`.
maxokorokov added a commit that referenced this issue Feb 21, 2020
Fixes #2922

BREAKING CHANGE:

'ngbDate' validator error messages were changed to be more explicit and aligned with Angular validators.
For the following use-case `<ngb-datepicker [ngModel]="{year: 2019, month: 12, day: 31}" [minDate]="{year: 2020, month: 1, day: 1}"></ngb-datepicker>` form control errors are:

Before

```
ngbDate: {
  requiredBefore: { year: 2020, month: 1, day: 1 }
}
```

After

```
ngbDate: {
  minDate: {
    minDate: { year: 2020, month: 1, day: 1 },
    actual: { year: 2019, month: 12, day: 31 }
}
```

Same change is applied for `requiredAfter` and `maxDate`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants