Form - End date cannot be before start date

Hi,
I have a form which captures the start date and end date of someone’s planned time off. Is there a code snippet for ensuring that someone cannot select an end date that is before the start date. Example: Start Date January 7th, End Date January 4th → should not be allowed/throw an error message “End date cannot be before Start date.”

Thanks!

Hello, Catalina!
Thank you for your question. It’s not difficult to do. Paste this code to the screen JavaScript with the form:

Fliplet.Hooks.on('beforeFormSubmit', function(data) {
  //if 'End Date' is before the 'Start Date' -> show an error message
  if (moment(data['End Date']).isBefore(data['Start Date'])){
    Fliplet.UI.Toast('Error!');
    return Promise.reject(); //the form won't be submitted
  }
  return data; //the form will be submitted if the condition is false
});

Replace ‘Start Date’ and ‘End Date’ with the names of your form fields.

You can read more about customising the error message in this documentation: Fliplet.UI.Toast() | Fliplet Developers Documentation

Please, let us know if it was helpful or you have any other questions.