Limit date picker to years only


#1

Is there a way to initialize the date picker so that the user can only pick a year and not a specific day or month?


#2

Hi @Vincent_Wansink :wave:

Yup, that’s totally possible!
You need to use the dateWheels option, explained here: https://docs.mobiscroll.com/jquery/datetime#localization-dateWheels.
Like this: dateWheels: 'yy'.
Let me know how it goes :wink:


#3

Well, that sounds promising but I can’t get it to work. Here’s my code.

$(function(){

  $('#pageyear').mobiscroll().calendar({
    'focusOnClose':false,
    'defaultValue':'<?php echo $currentyear; ?>',
    dateWheels: 'yy'
  });

});

But it still pops up with a regular calendar. What am I doing wrong?


#4

Hello Vincent :wave:

Ok, now I got it!
The problem is that you can’t set a yer only picker in the Calendar.
But a solution could be to use the Date & Time picker component.
In that component you can achieve this easily with dateWheels option, as I mentioned earlier.
Example:

$('#demo').mobiscroll().date({
    dateWheels: 'yy',
    dateFormat: 'yy',
});

Let me know if this make sense.


#5

Yes, that works. Thanks!