Need to validate the end date is not before the start date onSubmit

Julie Catano
Kilo Guru

When a customer is requesting a report for a period of time from start date to end date.  I need to validate onSubmit that the end date is not before the start date and it needs to not allow it to be submitted until corrected.

 

My variable field names - 'time_period_of_interest_start_date' and 'time_period_of_interest_end_date'

 

6 REPLIES 6

Hi,

Would appreciate a screenshot of variable definition.

Also, what would the alert show when onSubmit script is changed as follows.

function onSubmit() {
    try {
        var startDate = getDateFromFormat(g_form.getValue('time_period_of_interest_start_date'), g_user_date_format);
        var endDate = getDateFromFormat(g_form.getValue('time_period_of_interest_end_date'), g_user_date_format);
        alert('start:' + startDate + ' endDate:' + endDate + ' date format:' + g_user_date_format);
        if (startDate > endDate) {
            g_form.clearMessages();
            g_form.addErrorMessage('End date should be after start date');
            return false;
        }
    } catch (e) {
        alert(e.message);
    }
}

Julie Catano
Kilo Guru

I put this code into OnSubmit and I got a box to popup but it did not give an error message.

These are the variables.

This was the error