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

Date range limits in NgbDatepickerConfig can't be reset during runtime #4070

Closed
AlaaOthman98 opened this issue Apr 18, 2021 · 5 comments
Closed

Comments

@AlaaOthman98
Copy link

AlaaOthman98 commented Apr 18, 2021

Bug description:

I am trying to make limits for date range during runtime depending on some dates that I will get from my project API. I am using NgbDatepickerConfig to set minDate and maxDate, although the configuration object is changed, the date picker still wasn't affected by these updates even if it is reflected with the changes of configurations that are in the component's constructor during initialization. I searched in the previous issues but I didn't get a working solution and the issue still exist.

Link to minimally-working StackBlitz that reproduces the issue:

Here is a demonstration link: StackBlitz

Versions of Angular, ng-bootstrap, and Bootstrap:

In my working project versions are:

Angular: 11.0.5

ng-bootstrap: 8.0.0

Bootstrap: 4.5.3

@jnizet
Copy link
Member

jnizet commented Apr 19, 2021

Your demo changes the config after the datepicker has been constructed. The datepicker reads the config values at construction time, but doesn't watch the configuration changes. If you call this.changeDateLimits(); in the constructor of your component, the datepicker wil see the correct limits when it's constructed and use them.

So, either make sure to avoid constructing he datepicker before its configuration is ready, or pass minDate and maxDate inputs to the datepicker directly.

@AlaaOthman98
Copy link
Author

AlaaOthman98 commented Apr 19, 2021

This is what I need, I want to change the configuration of the date picker and set the limits after constructing the date picker as the limits are not known until I got them from an API. So, is there any solution to perform this action after constructing the date picker?

Also note that these limits (minDate - maxDate) are changed constantly during runtime depending on some user selections, so the component will be already initialized and the limits are changed.

@AlaaOthman98
Copy link
Author

#3438
Here in this issue, the author describes the same problem that I face, and it is written that this issue was solved in #3507 but I am still facing it.

@jnizet
Copy link
Member

jnizet commented Apr 20, 2021

I think I already provided a solution above. Changing the config is only useful for datepickers created after the change, because the config is used to initialize the datepicker inputs.
To change the inputs of existing datepickers, do just that: change their inputs: https://stackblitz.com/edit/angular-xlogwq?file=src%2Fapp%2Fapp.component.ts.

@AlaaOthman98
Copy link
Author

@jnizet Awesome, thanks a lot for your help!

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

No branches or pull requests

2 participants