Category: How do I do X?
Updated

This solution is summarized from an archived support forum post. This information may have changed. If you notice an error, please let us know in Discord.

Handling empty field values in validation

Issue

I need to ensure that the End Date inputted is at least one day after the Start Date. However, if the Start Date hasn't been entered yet, the End Date should be allowed to be any date after today. I'm wondering if using {{input_startDate.selectedDate ? moment(input_startDate.selectedDate).add(1, ‘d’).format() : moment().format()}} in the Min Date property would work for this.

Resolution

To prevent errors on field validation for a minimum End Date based on the Start Date, you can use the Min Date property of your End Date field. If the Start Date has not been entered yet, and you want to allow the user to enter any End Date after today's date, you can use the following code in the Min Date property:

{{input_startDate.selectedDate ? moment(input_startDate.selectedDate).add(1, ‘d’).format() : moment().format()}}

This code checks if the Start Date is entered or not. If it is entered, the code adds one day to the Start Date using the Moment.js library. If it's not entered yet, the code uses today's date as the minimum End Date.

However, if you want to allow any minimum End Date if there is no Start Date defined, you can modify the code to the following:

{{input_startDate.selectedDate ? moment(input_startDate.selectedDate).add(1, ‘d’).format() : ""}}

This code sets the minimum End Date to an empty string if no Start Date is defined.