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

Make min date as default when calendar opens #256

Closed
dgroh opened this issue Oct 19, 2017 · 16 comments
Closed

Make min date as default when calendar opens #256

dgroh opened this issue Oct 19, 2017 · 16 comments

Comments

@dgroh
Copy link

dgroh commented Oct 19, 2017

Is it possible to make a default date in calendar if I set it to min?

Scenario: The current date is 10-19-2017, but the min date that the user can select is 12-01-2017

When the user opens the DatePicker, he is going to see 10-19-2017 and won't understand what is happening. This is a common feature for the most of DatePicker controls.

Using displayDate could solve this, but thing is we don't want so show anything in the input so long the user has not picked any date.

@vlio20
Copy link
Owner

vlio20 commented Oct 19, 2017

dislplayDate is only made to open the calendar on specific date.

@dgroh
Copy link
Author

dgroh commented Oct 19, 2017

That is ok, but what about my question? Does this make sense? I can try a PR if you want I think that is a very useful feature.

@vlio20
Copy link
Owner

vlio20 commented Oct 19, 2017

I don't understand why dispalayDate doesn't solve your case

@dgroh
Copy link
Author

dgroh commented Oct 20, 2017

Because we don’t want to display anything until the user picks a day. It doesn’t make sense to show in calendar the current date if the min date is set for later. I’ll create a stackblitz to demonstrate the behavior

@dgroh
Copy link
Author

dgroh commented Oct 20, 2017

I'm trying to create a Stackblitz with moment but it does not work: https://stackblitz.com/edit/angular-trty1e

It says that moment is not a function.

@vlio20
Copy link
Owner

vlio20 commented Oct 20, 2017

try this one: https://stackblitz.com/edit/angular-1e7a7vv

@dgroh
Copy link
Author

dgroh commented Oct 20, 2017

I get:

Yikes! The page you requested couldn't be found.
If you think this is a bug/problem on our end, please file an issue over at https://github.com/stackblitz/core

@dgroh
Copy link
Author

dgroh commented Oct 20, 2017

Ok I got it to work: https://stackblitz.com/edit/angular-trty1e

Note that although the min date is december, when the picker opens it shows the current month. This does not make sense. If you check other datepickers you will see that the min is always the default date, for example:

https://dojo.telerik.com/IzEfI

@vlio20
Copy link
Owner

vlio20 commented Oct 20, 2017

@dgroh, it make sense. I will implement it in the next version (2.6.0)

@vlio20 vlio20 added this to the 2.6.0 milestone Oct 20, 2017
@dgroh
Copy link
Author

dgroh commented Oct 20, 2017

Brilliant much appreciated

@vlio20
Copy link
Owner

vlio20 commented Oct 22, 2017

resolved in 5663b7a

@vlio20 vlio20 closed this as completed Oct 22, 2017
@ld-gary
Copy link

ld-gary commented Dec 14, 2017

Hey,

Sorry to open this again but I am trying to implement this exact behaviour and have the latest version, but no joy.

Below is my initialisation of the config object, setting a time of 12:30 the next day, followed by the picker instance in the view. Feel free to let me know if I'm being stupid but I can't see what I'm doing wrong?

Thanks!

let findTomorrow = moment(new Date()).set({'hour': 12, 'minute': 30, 'second': 0}).add(1,'days');

this.tomorrow = findTomorrow.format("DD MMM [at] HH:mm");

this.dateConfig = { format: "DD MMM [at] HH:mm", min: this.tomorrow, showTwentyFourHours: true, disableKeypress: true, minutesInterval: 15 };

----- Date Picker Instance -----

<dp-date-picker *ngIf="showDatePicker" #Picker formControlName="temp_date" (ngModelChange)="dateToChange($event, false)" (close)="dpClosed(false)" [config]="dateConfig" theme="dp-material" [placeholder]="date_open ? '' : 'Set Date & Time'" mode="daytime"></dp-date-picker>

@vlio20
Copy link
Owner

vlio20 commented Dec 15, 2017

pls provide a stackblitz

@ld-gary
Copy link

ld-gary commented Dec 15, 2017

@ld-gary
Copy link

ld-gary commented Dec 15, 2017

So as I understand it, setting the min parameter of the config object to a particular date should select that date if the current date is earlier?

@ld-gary
Copy link

ld-gary commented Dec 31, 2017

Hey, just an update/clarification. The above code and the original stackblitz had the date strings formatted in such a way that there was no year present ("DD MMM [at] HH:mm"). I have updated in my code and on the stackblitz which half solves the issue in that the picker opens on the minimum date, but the time is still just set to whatever time it is when the page loads.

I understand that setting the model (or control name) does cause the picker to open at a specified time, but I don't want to actually have to set the date and time on load. I just want the picker to open at the date and time that corresponds to the minDate value. Can it be done in a way that I am missing?

Thanks and Happy New Year!

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

No branches or pull requests

3 participants