Tempus-dominus: viewMode not remembered

Created on 7 Oct 2016  路  12Comments  路  Source: Eonasdan/tempus-dominus

Initializing with:

viewMode: 'years',
format: 'YYYY-MM-DD',
useCurrent: false,
allowInputToggle: true,

I'm using useCurrent: false so that if the user does NOT click on anything within the picker (e.g. clicks off the picker to close it) that the default current date will not be entered into the field.

With the viewMode setting the picker should open into the "years" mode as set. The first time it is opened this is true:
screen shot 2016-10-06 at 3 25 45 pm

The second time (any subsequent times the picker is opened) the viewMode is NOT respected EVEN though there is no date in the field:
screen shot 2016-10-06 at 3 25 51 pm

ViewMode should be respected as long as no date has been selected.

Most helpful comment

One fix that does work is to reset the viewMode (even though the option is correct already) when the picker is closed via a timeout (so it fires after other code). VERY DIRTY BUT WORKS!

$('#Years').on('dp.hide', function(event){
  setTimeout(function(){
    $('#Years').data('DateTimePicker').viewMode('years');
  },1);
});

All 12 comments

Update: This looks like a duplicate of #1802 #1809, so a fix may be in the works.

I also see this issue. It seems to be related to 4.17.42. I have a Knockout Component wrapper for the DateTimePicker. It works fine on 4.15.35:

See the _Period End Date_ field in the demo
http://codepen.io/bjsafdie/pen/ee515a6e09e5fb268132c71e7dcfb2d4

When I updated to 4.17.43 I saw the issue. I checked each release above 4.15.35. 4.17.37 works. 4.17.42 seems to be the first release where I see the behavior described above:

http://codepen.io/bjsafdie/pen/e83f73514dc2da44325aeb12b3615b10

Unlike phippster, I am using viewMode: 'months' and format: 'MMM, YYYY' -- no Days in the format. However, the days view is still shown after the first picker opening.

so what i have to do ?

This isn't related to useCurrent: false as I have removed this option and still see the issue on the second time the picker is opened. Hopefully a fix will be in place soon.

Also check the options with $('#Months').data('DateTimePicker').options(); reveals that the viewMode is still correct but that the picker itself doesn't honour it!

Is their a short term fix that can be applied to solve this until a patch is created?

One fix that does work is to reset the viewMode (even though the option is correct already) when the picker is closed via a timeout (so it fires after other code). VERY DIRTY BUT WORKS!

$('#Years').on('dp.hide', function(event){
  setTimeout(function(){
    $('#Years').data('DateTimePicker').viewMode('years');
  },1);
});

^
thanks, I'll give a try

Same here, it doesn't work for me as well.
From what I saw, the issue is with
currentViewMode = 0; at the end of the hide function.
Instead it should be:
currentViewMode = minViewModeNumber;

+1 to this issue, I have this:

$('#selector').datetimepicker({
    locale: "es",
    format: "MM-YYYY",
    viewMode: "years"
});

it lets you pick year and month the first time but if clicked again it shows the complete date calendar picker (although if you click a day it doesn't change the input as format only recognizes months and years)

Hi, this was solved on latest version.
https://jsfiddle.net/William_/ja6v6x2x/

Was this page helpful?
0 / 5 - 0 ratings