Does JotForm offer a year only field?

  • wsrhodes
    Asked on May 24, 2017 at 3:44 PM

    I want to have a field where they enter a year, but also want it to recognize a) valid years and b) not allow future. Is this possible without a lot of custom coding?

  • Support_Management Jotform Support
    Replied on May 24, 2017 at 5:27 PM

    We don't have a field like that but this should be achievable by using a Number Field, a Text Field and Conditions.

    The Number Field will act as the Year Field. A Text Field will be needed to show an error/warning to the user that they entered an invalid year. And Conditions will be used to check the value entered on the Number Field.

    Here's an example of how a Condition may look like to check the value of the user's entry.

    e.g. values outside 1900 and 2017 are invalid

    Does JotForm offer a year only field? Image 1 Screenshot 20

    Related guides:

    Smart-Forms-Using-Conditional-Logic

    How-to-Show-or-Hide-Fields-Base-on-User-s-Answer

    Conditional-Logic-Inserts-Text-Calculation-Into-A-Field 

    Give it a spin and let us know if you'd need more help.

  • wsrhodes
    Replied on May 25, 2017 at 8:08 AM

    Thank you Jim.  This is a good solution.  One follow up question: For the "value" field, can I use a dynamic field like "today" or "current year"? That way i don't have to change my form as time goes by. For example, in your version above, the "Greater than" value should always be "current year".

  • wsrhodes
    Replied on May 25, 2017 at 8:50 AM

    can I reference just the "year" portion of a (current) date field in a form calculation widget?

     

  • candy
    Replied on May 25, 2017 at 11:29 AM

    Hello,

    The only way that we can get the Year only from the Date field is with the help of a text field and the Substring widget.

    I have set a condition in order to receive the current date as a string format. After, I have set a Substring widget in order to cut only the year part.

    Please check the following example form and feel free to clone it on your side in order to test it: https://form.jotform.com/71363338823963

    However, I have realized that we need to enter any character to the string date field in order to receive the only year. I will investigate this issue.

    I hope this helps you for now.

    Thanks.

  • wsrhodes
    Replied on May 25, 2017 at 11:36 AM

    Thanks Candy. Not sure that helps. I don't understand why it is so hard to have a "Current-year" field that can be used to compare to other entered field data.

  • Support_Management Jotform Support
    Replied on May 25, 2017 at 1:25 PM

    can I reference just the "year" portion of a (current) date field in a form calculation widget?

    I'm afraid you'd have to compare the user's input with the entire date (YYYY-MM-DD). However, you can still achieve the same if you will go with using the regular Date Picker field.

    Basically what you'd do are the following:

    1. Use the default Date Picker field

    2. Hide the Month and Date fields via CSS (optional, it's totally up to you)

    3. Then use Conditions to check for the year

    e.g. You want to filter out dates from Jan 1, 1900 up to Today

    You can use the same solution I've given on my earlier reply, only this time, instead of GREATER THAN / LESS THAN, you'd use BEFORE / AFTER.

    Does JotForm offer a year only field? Image 1 Screenshot 30

    On a minor note, I was mistaken with the screenshot I sent on my previous reply. Instead of selecting ALL, you should pick ANY.

    Does JotForm offer a year only field? Image 2 Screenshot 41

    If you will go with my suggestion, I recommend you build your form and get back to us once you're about to implement the CSS codes you need to hide the month and date fields. We need the form completed first so we can give you the proper selectors to be targeted for the CSS.