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

How to set the default date when showing the picker at the first time? #426

Closed
nicolasblanco opened this Issue Jul 22, 2014 · 9 comments

Comments

Projects
None yet
7 participants
@nicolasblanco

nicolasblanco commented Jul 22, 2014

Hi,

if I set the defaultDate option, it sets the field with that value during the initialization of the picker.

I would like to keep the field empty if the user does not show the picker but be able to set
the default date when the picker is clicked the first time.

How is that possible?

Thanks.

@Eonasdan

This comment has been minimized.

Show comment
Hide comment
@Eonasdan

Eonasdan Jul 22, 2014

Owner

Just don't set defaultDate and leave useCurrent as true. With useCurrent the picker will populate the text box on first click with today's date.

Owner

Eonasdan commented Jul 22, 2014

Just don't set defaultDate and leave useCurrent as true. With useCurrent the picker will populate the text box on first click with today's date.

@nicolasblanco

This comment has been minimized.

Show comment
Hide comment
@nicolasblanco

nicolasblanco Jul 22, 2014

@Eonasdan : I would like to manually specify the default date when the user first click on the date time picker.
In my use case : I would like to initialize the default date at 00:00, not the current hour.

Thanks.

nicolasblanco commented Jul 22, 2014

@Eonasdan : I would like to manually specify the default date when the user first click on the date time picker.
In my use case : I would like to initialize the default date at 00:00, not the current hour.

Thanks.

@Eonasdan

This comment has been minimized.

Show comment
Hide comment
@Eonasdan

Eonasdan Jul 22, 2014

Owner

what's the use case here?

If the user has opened the picker, why do you need to set the date?

Owner

Eonasdan commented Jul 22, 2014

what's the use case here?

If the user has opened the picker, why do you need to set the date?

@nicolasblanco

This comment has been minimized.

Show comment
Hide comment
@nicolasblanco

nicolasblanco Jul 22, 2014

@Eonasdan :
If the current date is 2014-07-22 17:45 and the user clicks on the picker, I would like the date to be 2014-07-22 00:00.

nicolasblanco commented Jul 22, 2014

@Eonasdan :
If the current date is 2014-07-22 17:45 and the user clicks on the picker, I would like the date to be 2014-07-22 00:00.

@cdarken

This comment has been minimized.

Show comment
Hide comment
@cdarken

cdarken Aug 7, 2014

Yeah, some users require this, I was thinking the same, but clients are clients, and you can't convince them.
I had to work around this problem, by setting a class like 'empty' on the empty inputs then listen for the dp.change event and if the triggered input had that class I would set the hours and minutes to 0 then remove the class. It would be nice to have an option like empty-format where you can set for instance DD/MM/YYYY 00:00, which works if you set it as default format, but it ignores the hours and minutes that you choose.

cdarken commented Aug 7, 2014

Yeah, some users require this, I was thinking the same, but clients are clients, and you can't convince them.
I had to work around this problem, by setting a class like 'empty' on the empty inputs then listen for the dp.change event and if the triggered input had that class I would set the hours and minutes to 0 then remove the class. It would be nice to have an option like empty-format where you can set for instance DD/MM/YYYY 00:00, which works if you set it as default format, but it ignores the hours and minutes that you choose.

@nikoskalogridis

This comment has been minimized.

Show comment
Hide comment
@nikoskalogridis

nikoskalogridis Aug 7, 2014

Contributor

We could easily implement this in case the pickTime is set to false. But that would brake the current behaviour so I don't think that is a good idea.
One other option is to set the useCurrent option to a string ('year', 'month', 'day', 'hour', 'minute') specifying the required granularity when opening the picker for the first time. That would keep the current behaviour hence not braking old code and adapt to new code in case it finds a string

Contributor

nikoskalogridis commented Aug 7, 2014

We could easily implement this in case the pickTime is set to false. But that would brake the current behaviour so I don't think that is a good idea.
One other option is to set the useCurrent option to a string ('year', 'month', 'day', 'hour', 'minute') specifying the required granularity when opening the picker for the first time. That would keep the current behaviour hence not braking old code and adapt to new code in case it finds a string

@nikoskalogridis nikoskalogridis added this to the 4.0.0 milestone Aug 9, 2014

@nikoskalogridis nikoskalogridis self-assigned this Aug 9, 2014

nikoskalogridis added a commit that referenced this issue Aug 9, 2014

@pmarsilio

This comment has been minimized.

Show comment
Hide comment
@pmarsilio

pmarsilio Sep 25, 2014

Hi,
I also need to default the input to a date but only if the user activate the picker.
I am not quite sure if this was implemented yet or maybe I am not using it right.
I and using this option:
useCurrent:'2012-10-24 22:02:00'
thanks for helping

pmarsilio commented Sep 25, 2014

Hi,
I also need to default the input to a date but only if the user activate the picker.
I am not quite sure if this was implemented yet or maybe I am not using it right.
I and using this option:
useCurrent:'2012-10-24 22:02:00'
thanks for helping

@sellittf

This comment has been minimized.

Show comment
Hide comment
@sellittf

sellittf Jan 29, 2016

$("#myDateTimePicker").datetimepicker({
  useCurrent: false
}).on('dp.show', function() {
  return $(this).data('DateTimePicker').defaultDate(new Date());
});

sellittf commented Jan 29, 2016

$("#myDateTimePicker").datetimepicker({
  useCurrent: false
}).on('dp.show', function() {
  return $(this).data('DateTimePicker').defaultDate(new Date());
});
@valix85

This comment has been minimized.

Show comment
Hide comment
@valix85

valix85 May 5, 2016

My solution for @pmarsilio

var firstOpen = true;
$(function(){
$('#nascita').datetimepicker({
    locale: 'it',
    viewMode: 'years',
    format: 'DD/MM/YYYY',
}).on("dp.show", function(){
    console.log("dtp open");
    if (firstOpen==true){
        $(this).data('DateTimePicker').date("01/01/1980");
        firstOpen=false;
    }
});
});

valix85 commented May 5, 2016

My solution for @pmarsilio

var firstOpen = true;
$(function(){
$('#nascita').datetimepicker({
    locale: 'it',
    viewMode: 'years',
    format: 'DD/MM/YYYY',
}).on("dp.show", function(){
    console.log("dtp open");
    if (firstOpen==true){
        $(this).data('DateTimePicker').date("01/01/1980");
        firstOpen=false;
    }
});
});

Repository owner locked and limited conversation to collaborators May 5, 2016

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.