im having the exact same issue but with a different format, format is YYYY
viewMode: 'years',
format: 'YYYY'
look https://jsfiddle.net/dugujianxiao/ad64awL7/11/
added viewMode months
second click display days viewMode
Same here. #1897 seems to be a duplicate.
so, That this is a bug?
@stevieyu i think it is. If I setup the picker to only show years, it should only show years on every click on the input. Now it shows years on first click, and a full calendar (days, months and years) on second and next clicks.
@stevieyu yeah it's definitely bug. I have the same bug on some of my projects.
Let's hope they'll fix it asap.
+1
I've got two temporary fixes you can put in place, just done some testing myself as I needed this fixed.
Set the input to detect when the datetimepicker is shown, and set the viewmode there, bit lazy, I know.
$("#elementId").on("dp.show", function(e) { $(e.target).data("DateTimePicker").viewMode("months"); })
Alternatively, another fix that works much better. It seems, when the datetimepicker hides/closes. It will set the currentViewMode to 0, which essentially resets it back to days. If you change this line of code, on line 937.
currentViewMode = 0; to currentViewMode = minViewModeNumber;
It will set it to the format when first initialized, and changing the viewMode will work. Do note, it won't go below the format you've specified, so if you've done MM-YYYY, setting viewMode to days won't work as it's lower than months, but I don't see why you'd want to see the days when only showing the month and year.
Hope this helps!
Edit: Seems there needs to be a feature added where you can set the minViewModeNumber, as it's reliant on the format of your format string, if it has 'D' in it will be min of days, else if has 'M' min will be months, else if has 'Y' min will be years. So 'YYYY MM DD' will always have min of days, whilst 'MM-YYYY' will have min of months. So, even if you change the viewMode, it can't go below the format.
I confirm the problem. When will the correction?
@ilflask you'd read @keegars 's answer. It works pretty well, and still we're agree that a feature should be added ( like minViewModeNumber )
Duplicate of #1854.
Hi, this has been solved on latest version so I'll be closing this
Most helpful comment
I've got two temporary fixes you can put in place, just done some testing myself as I needed this fixed.
Set the input to detect when the datetimepicker is shown, and set the viewmode there, bit lazy, I know.
$("#elementId").on("dp.show", function(e) { $(e.target).data("DateTimePicker").viewMode("months"); })Alternatively, another fix that works much better. It seems, when the datetimepicker hides/closes. It will set the currentViewMode to 0, which essentially resets it back to days. If you change this line of code, on line 937.
currentViewMode = 0;tocurrentViewMode = minViewModeNumber;It will set it to the format when first initialized, and changing the viewMode will work. Do note, it won't go below the format you've specified, so if you've done MM-YYYY, setting viewMode to days won't work as it's lower than months, but I don't see why you'd want to see the days when only showing the month and year.
Hope this helps!
Edit: Seems there needs to be a feature added where you can set the minViewModeNumber, as it's reliant on the format of your format string, if it has 'D' in it will be min of days, else if has 'M' min will be months, else if has 'Y' min will be years. So 'YYYY MM DD' will always have min of days, whilst 'MM-YYYY' will have min of months. So, even if you change the viewMode, it can't go below the format.