sitecoresitecore7

Sitecore Datefield - Year only for Content Editors


As per text fields where you can provide parameters to show various rich text editor views is there a similar set of parameters for datefield to only present the Editor with a Year Range when selecting a date?

While the Editor can currently click back each month on the calendar multiple times it seems it is a lot of clicking to go back years. Easiest solution so far has been to select TODAY and then manually have the editor type 1/1 of the year they require - not very user friendly but if I can default to a year view that would be best


Solution

  • It is not possible in Sitecore to change the DateField field to display year selector only and I don't see any functionality which would allow to set the range of the years in the selection.

    However you can use another field type: Droplist (yes, Droplist, not Droplink). You just create in Sitecore a structure like:

    - Allowed Years
        - 1961
        - 1962
        - 1963
        - ...
    

    And point to that item in the Source of your Droplist field. The value which is stored in your item is the name of the selected item, not guid, so you will get 1961 without a need to get the year item first.


    EDIT

    You can also have a look at Unbound droplist custom field type:

    https://marketplace.sitecore.net/en/Modules/Unbound_Droplist.aspx

    It was written for Sitecore 6 but I don't see any reason why it should not work with newer Sitecore versions. It allows you to specify values for your droplist as pipe separated value in the Source field, instead of creating those items in Sitecore.