We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

Client script for current and future dates

Archana23
Tera Contributor

I need client script for allowing only current and future dates.

4 REPLIES 4

Not applicable

function onLoad() {
var dateField = g_form.getControl('date_field_name');
var today = new Date().setHours(0, 0, 0, 0);
dateField.setMin(today);
}

function onSubmit() {
var dateFieldValue = g_form.getValue('date_field_name');
var selectedDate = new Date(dateFieldValue).setHours(0, 0, 0, 0);
var today = new Date().setHours(0, 0, 0, 0);
if (selectedDate < today) {
g_form.addErrorMessage('Please select a current or future date.');
return false;
}
return true;
}

 

//Replace "date_field_name" with the actual name of your date field.

Prince Arora
Tera Sage

@Archana23 ,

 

You can achieve this functionality using UI policy also. I made an example on created field you can mention your field name in the filter

PRINCE_ARORA_0-1677172635036.png

PRINCE_ARORA_1-1677172676775.png

 

If my answer solved your issue, please mark my answer as Correct & 👍Helpful based on the Impact.

Hey Prince,

I wanted to let you know that this method doesn't work on a custom workspace.

 

Thanks,

Gonzalo

Prince Arora
Tera Sage

@Archana23 ,

Please accept the solution if it works for you!