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/max dates are not disabled in popup #3598

Closed
sleptsov opened this issue Feb 15, 2020 · 3 comments · Fixed by #3686
Closed

Min/max dates are not disabled in popup #3598

sleptsov opened this issue Feb 15, 2020 · 3 comments · Fixed by #3686

Comments

@sleptsov
Copy link

Bug description:

Dates in datepicker popup do not set to disabled state when use dynamic [minDate]/[maxDate] with custom date adapter

In a forked demo from ng-bootstrap Custom date adapter and formatter you can see that min/max is set dynamically from component class and disabled in basic UI mode, but not in a popup UI mode, if remove (comment out) custom adapter from providers array dates (min/max) are becoming disabled

Link to minimally-working StackBlitz that reproduces the issue:

https://stackblitz.com/edit/angular-oetchw

Versions of Angular, ng-bootstrap and Bootstrap:

Angular: 8.2.14

ng-bootstrap: 5.3.0

Bootstrap: 4.4.1

@artopaavola
Copy link

This seems to have been working correctly in 5.2.1 and is broken in 5.2.2 ->

@ar41bald
Copy link

ar41bald commented Mar 10, 2020

I have the same issue even with the built-in NgbDateNativeAdapter.

Link to minimally-working StackBlitz that reproduces the issue:

https://stackblitz.com/edit/angular-zdyuru?file=app%2Fdatepicker-popup.ts

As I can see in the date-picker sourcecode the problem is that this provided adapter is used to convert @input minDate/maxDate (using toModel method) but it shouldn't as minDate/maxDate are always NgbDateStruct objects by design.
Here is the line from ng-bootstrap source code

this._cRef.instance.minDate = this._dateAdapter.toModel(changes.minDate.currentValue);
...
this._cRef.instance.maxDate = this._dateAdapter.toModel(changes.maxDate.currentValue);

After these lines executed with the changes like this: {year: 2020, month: 3, day: 1}, minDate/maxDate are set to JS Date objects and then they couldn't pass validation in the NgbDatePickerService and became null

    let patch = Object.keys(options)
                    .map(key => this._VALIDATORS[key](options[key]))
                    .reduce((obj, part) => ({...obj, ...part}), {});

In my opinion, the solution is - refactor setting minDate/maxDate changes to avoid transforming them by any adapter.

@maxokorokov
Copy link
Member

@ar41bald thanks for getting to the bottom of this issue. Confirm it was broken in 5.2.2, apologies it took so long.

Fix should be released in 5.3.1 and 6.0.3

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.

5 participants