Prevent catalog submission based on date field in text box (string field) in MRV

reddy8055
Tera Contributor

Hi,

I am populating date field in string field in MRV and want to prevent submitting the form if any of the date is more than 365 days with today's date and if it falls less than 365 days then form should be submitted.  I have written onsubmit client script but Its not checking for all date fields (in rows)

reddy8055_0-1668743136588.png

 

 

function onSubmit() {
var today = new Date();
//today.setHours(0,0,0,0);
var startDTe = g_form.getValue('course_completed_date');
//alert(startDTe);
var startDateNum = getDateFromFormat(startDTe, g_user_date_format);
var coursedate = today - startDateNum;
alert(coursedate);
var dayDifference = coursedate / (1000 * 60 * 60 * 24);
// alert(dayDifference);
if (dayDifference > 365) {
return false;
}

return true;
}

 

Thanks,

10 REPLIES 10

You don't need the return true line as that won't do anything - return true is the default unless you meet a condition where it should return false to prevent the submit.  Alert on today just to make sure that is what you expect, and also alert on mrvs before the parse so you can see what it is trying to parse.  You should never name a variable, variable set, or function with reserved words, so also try changing your MRVS internal name to something more than 'date' like even 'date_mrvs'.