Date Picker: How to set as default date the first of the month?

  • nikifox
    Asked on May 28, 2020 at 5:28 PM

    Hello,

    I would like to set the custom default date for a Date Picker question to be the first of the current month, but I only see an option to set it to a fixed date.

    How can I set it so that the default date automatically updates to reflect the current month every month?  Ex: next month the default date would change to 2020-5-1.

    Thank you!

    Jotform Thread 2353881 Screenshot
  • Kevin Support Team Lead
    Replied on May 28, 2020 at 9:06 PM

    This is not currently possible to do with the current date picker settings or the available widgets, I have been performing some tests and was unable to find a workaround for this, we may however open a feature request for this, although we cannot provide an ETA, we would keep you updated via this ticket, kindly confirm so we can proceed with the request. 


  • Kevin Support Team Lead
    Replied on May 28, 2020 at 9:41 PM

    I found a workaround using the Date Picker and the Substring widgets, here are the steps: 

    - First add the following elements to your form: 

    1. Date Picker widget, you will find it under the widgets tab. 

    2. Substring widget.

    3. A short text entry field. 

    15907157632020 05 28 19h28 14 Screenshot 10

    - The date picker widget must be configured like this:

    15907160222020 05 28 19h29 46 Screenshot 21

    - The Substring widget must be configured like this:

    15907160562020 05 28 19h29 29 Screenshot 32

    On this widget you will also use the field ID, you may refer to this guide for more details about how to get this: https://www.jotform.com/help/146-How-to-Find-Field-IDs-and-Names 

    This widget will basically get the month and year, that's why the date format is important. 

    - The last step is to copy the value from the Substring widget and insert it to the short text field adding the day, here is how your condition should be configured: 

    15907163472020 05 28 19h38 49 Screenshot 43

    The elements should be added as text, by default they are added as numeric values, but you can click on the element to add it as text. 

    This guide will also help you setting up this type of conditions: https://www.jotform.com/help/268-How-to-Insert-Text-or-Calculation-into-a-Field-Using-Conditional-Logic 

    You can test this on my form: https://form.jotform.com/201488327170959 

    Feel free to change the date in order to see how it's updated.

    I hope this helps. 

  • nikifox
    Replied on June 3, 2020 at 4:00 PM

    Hi Kevin,

    Thank you for your solution!  However there seems to be an issue with the Substring function on my form.  I tried following your steps, and various other tests, but the substring does not return a value from the Date Picker widget.  I used the ID from the "Field ID" section of the Date Picker.  Also, the number in the calculation (0, 1) will not save as text- if I click them to make them grey and save, the next time I open the calculations they are black again.

    Please advise on how to get Substring to work, thanks!

    1591214255Substring Screenshot 101591214280Calculations Screenshot 211591214290Result Screenshot 32

  • David JotForm Support Manager
    Replied on June 3, 2020 at 9:28 PM

    Hi, the Substring widget requires using the field ID. You are using the Card Forms layout, and in this layout, the field does not have an ID.

    You can solve this by:

    1) Switching the layout to the Classic one: https://www.jotform.com/help/493-How-to-Change-the-Form-Layout

    2) Getting the ID of the Date Picker widget:

    1591233943id 001 Screenshot 10

    3) Put the ID in the Substring widget.

    4) Switch back to Cards layout.

    Result: https://form.jotform.com/201547938650966

    1591234061layout Screenshot 21

    Let us know if you need more help.

  • nikifox
    Replied on June 4, 2020 at 4:23 PM

    Thank you for the Field ID explanation.  I would like to hide the Current Date but use substring from it to populate the First Day of the Month, however when I hide Current Date the substrings do not return a value.

    Is there a workaround for this?

    Thanks!

  • David JotForm Support Manager
    Replied on June 4, 2020 at 7:01 PM

    Hi, I am afraid that there is no other workaround in the Card layout, the widget needs to show up, so the value can be passed to the substring widget.

    If you try the Classic layout, the widget can be hidden with CSS code:

    #id_267{

        visibility: hidden;

    }

    So, the value will still pass. Unfortunately, the Card layout does not allow CSS code injection.