Validation on date column value relative to today’s date

Applies to: SharePoint Online and SharePoint On-Premises

Description

NITRO Forms allow configuration of validations on form data. This can be based on data format (like email, phone etc.), length of entered data, specific values etc. Also, validations can be conditional based on data in other columns and even based on membership of logged-in user.

In some cases advanced validations may be required and these can be configured by adding the required script on the form. This article describes the steps to configure validation on a date column such that entered date should be at least 14 days from today (this validation is required only on the new item form).

Detailed Steps

Go to Site Content -> Navigate to the required list -> Click on List Settings -> Open Crow Canyon NITRO Forms.

In NITRO Forms designer left pane, click ‘Layouts and Theme’ section. Check “Hide Save Button” option and set “Bottom Action Panel Button Align” option to ‘Right’ as shown below:

 

Note: Form shown above is using separate forms for New / Edit / Display. This validation can be configured with common form as well by adding two separate submit action buttons. Configure permissions on one submit action for ‘ID’ as “is empty” and this button. With this condition, it will only be shown for new item form and validation script will be configured for this button as described below. For the other submit button, configure permissions for ‘ID’ as “is not empty” and this button will not have the script since it will be shown for edit and display of the items.

 

Next, drag and drop Submit Action from “Actions” menu in the left panel:

Click Submit Action button to show its properties in the right panel. Configure the button title, icon and validation script in the right panel.

Date column validation script:

var varDate = new Date();
varDate.setDate(varDate.getDate() + 14);
var dueDate = formContext.fetchColumnValueUI("DueDate");
var validationPassed = false;
if (dueDate) {
if (typeof dueDate == "string") {
dueDate = dueDate.replace(/-/g, " ");
}
validationPassed = Date.parse(dueDate) >= Date.parse(new Date(varDate.toDateString()));
}
if(validationPassed == false){
functionCallback(true, "Due Date cannot be less than 14 days from today");
return;
}
functionCallback();

Note: In the above script, “DueDate” is the internal name of the Date and Time column on the form for which validation is configured. Replace it with the internal name of the column on your form.

 

After adding the script, click Apply as shown above and publish the NITRO Forms. Note that you may have to refresh the actual NITRO form a couple of times as NITRO forms settings are cached to improve performance.