Calendar control - only month and year

  • 5 August 2022
  • 3 replies
  • 329 views

Badge +2

Hello,

 

I need to choose only the month and year on the form. Is there a change so that only the month and year can be selected in the calendar control? I saw that I can change the format, but the choice shows with the day.


3 replies

Userlevel 2
Badge +6

Hi @SaintGobain,


 


The calendar control will currently always show the day, irrespective of the format you display it in, with the added caveat that the resultant date that will be saved from the calendar will always include the day as well, which I'm guessing you don't want.


 


Honestly, if you only want the user to select a month and year, I would have a dropdown with 1-12 (or Jan to Dec, depending on what format you want) and a textbox that is defaulted to the current year and use some JS to change the textbox's type to number (you can substitute the name of your text box and you can get the current year using an expression, or drop the max if you want to allow dates in future): 


<script>$("[name='Year Text Box']").attr("type", "number"); $("[name='Year Text Box']").attr("max", "2022");</script>

 


Put the above JS as the Text value in a Data Label with Literal = true, Prevent XSS = false, the DL must be added to the canvas after the textbox. It will add a "spinner control" to the textbox that can be used to decrease/increase the year for easy entry. If you don't want to use any JS, I suggest you use a dropdown with hard-coded years.


 


HTH,


Ernie

You can set the control to only select a date, but there is not a setting for only month/year.  You could still use the calendar control, then use use the Month and Year functions to pull out those values.


 


 

Badge +2

Hi,
thanks for the exact solutions. I chose the option with the drop down list.

Thanks for your help

Reply