Date Validation
- This topic has 2 replies, 2 voices, and was last updated 2 years, 8 months ago by .
Viewing 2 reply threads
Viewing 2 reply threads
- You must be logged in to reply to this topic.
Home › Forums › Classic DFFS › Date Validation
I need to do a date validation to ensure date entered is between a start and end date field values. Can you please advise how I can do that? The following code works on false but does not save if true. Also I need to allow for blank fields as well.
function dffs_PreSaveAction(){
var startDate = spjs.utility.getDateFieldAsDateObject(‘StartDate’);
var endDate = spjs.utility.getDateFieldAsDateObject(‘EndDate’);
var dateAnswer1 = spjs.utility.getDateFieldAsDateObject(‘DateAnswer1’);
if (dateAnswer1 < startDate || dateAnswer1 > endDate) {
alert(‘DateAnswer1 must be greater than StartDate and less than EndDate’);
return false; // Return false to indicate validation failure
}
return true; // Return true to indicate validation success
}
Please disregard, I was able to get the following to work:
function dffs_PreSaveAction(){
var startDate = spjs.utility.getDateFieldAsDateObject(‘StartDate’);
var endDate = spjs.utility.getDateFieldAsDateObject(‘EndDate’);
var dateAnswer1 = spjs.utility.getDateFieldAsDateObject(‘DateAnswer1’);
if (dateAnswer1 > startDate && dateAnswer1 < endDate) {
return true;
}
else {
alert(“Date is not range”);
return false;
}
}
I’m glad you figured it out.
Alexander