Modal to let customer know they have entered a future date

Brad Campbell
Tera Contributor

Hi Community,

 

We have a use case for a new catalogue item where the user is to enter a value in a variable of date / time type but this date cannot be in the future. I found a great article which details how to do this and display an error message. But our preference is to use sp modal as in our experience customers see traditional error message pop ups as being a system rather than user issue.

 

I've used modals before and know how to create them, where I am struggling is the correct code to use comparing the variable (submitted_date) to the current date time so it knows to display the modal when the user tries to submit.

 

function onSubmit() {

    var submittedDate = g_form.getValue('submitted_date');

    if (typeof spModal != 'undefined' && !g_form._hasConfirmed && ??) {

        spModal.open({
            message: 'Date cannot be in the future',
            title: 'Future Date',
            buttons: [{
                label: 'OK',
                cancel: true
            }, ]
        }).then(function(confirm) {
            if (confirm) {
                g_form._hasConfirmed = true;
                if (typeof g_form.orderNow != 'undefined') {
                    g_form.orderNow();
                } else {
                    g_form.submit();
                }
            }
        });

        return false;
    }
}

 

Any help appreciated as always.

5 REPLIES 5

Hi Brad,

I have tested this logic for date/time field, seems to be working fine on pdi.

function onSubmit() {
	
    var currentDateTime = new Date();
    var dateTimeField = getDateFromFormat(g_form.getValue('selected_date_time_field'), g_user_date_time_format);

    if (dateFromField > currentDateVal) { 
		// Future date selected
        return false;
    }
}

 

If this works for you, please mark my answer correct or helpful.