modx revo tv type "of date" with a choice of only year

160 Views Asked by At

How to make TV of type "date" with choice of a year only? The option to enter any date of the year, and then output only "%Y" considered, it does not suit.

1

There are 1 best solutions below

0
Tony Klapatch On

Your question is a little hard to understand, but I think you are asking how to only have year selection (so no month and day selection) in a date template variable. The date template variable may not work ideally for this since it wants at least a day and month.

Small Set of Known Years

One solution could be to use a ListBox Single Select template variable if you have a limited set of known years to select from. Set each year you want as an input option value. For example, for the years 2017, 2018, 2019, and 2020 you would have: 2017||2018||2019||2020

However, this wouldn't be ideal for a larger potentially unknown range of years.

Larger Set of Years

Another solution could be to use a text field template variable and use the regex validator to check if it is a valid year. A simple check such as ^[12][0-9]{3}$ would make sure the input is a 4 digit year between 1000 and 2999.