Prevent Submitting the form if Multi row variable set is empty
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2022 08:44 PM
Hi,
I am populating multi row variable set based on requested for user info and want to prevent submitting the form whenever MRVS is empty. Tried mrvrs == '' like highlighted below in red but its not working.
function onSubmit() {
var today = new Date();
var mrvs = g_form.getValue('vta_training_details'); // internal name of your MRVS
alert(mrvs);
var obj = JSON.parse(mrvs);
for (var i = 0; i < obj.length; i++) {
var startDTe = obj[i].course_completed_date; // name of the MRVS variable
//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) || (mrvs == '') || (mrvs == null)) {
g_form.addErrorMessage("Course Completed Date should not be more than 365 days");
return false;
}
}
Thanks,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2022 08:49 PM
Hello,
You an just use individual variable name in the mvrs to validate this. If you want to stop prevention if any variable is empty then is it as field1==''|| field2==''
and if you want want prevent only if all the mvrs field are empty use field1==''&&field2==''
Please mark my answer as correct based on Impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2022 08:54 PM
Hi,
Tried like the below its not working. I am populating mrvs like tabular format so want to stop if all variables(whole set ) is empty
if ((dayDifference > 365) && (mrvs == '') && (mrvs == null)) {
Thanks,
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2022 08:58 PM
Hello,
Yes that is waht i was saying instad of taking the complete mvrs use the variables individually like below:-
if ((dayDifference > 365) && (mvrsfiedl1=='') && (mvrsfiedl2=='') && (mvrsfiedl2=='')) {
Please mark my answer as correct based on Impact.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-06-2022 09:09 PM
Its not working.
function onSubmit() {
var today = new Date();
var mrvs = g_form.getValue('vta_training_details'); // internal name of your MRVS
var x = g_form.getValue('course_completed_date');
var y = g_form.getValue('name');
var z = g_form.getValue('email');
var total = 0;
alert(mrvs);
var obj = JSON.parse(mrvs);
for (var i = 0; i < obj.length; i++) {
var startDTe = obj[i].course_completed_date; // name of the MRVS variable
total = total + parseInt(parser[i]).course_completed_date; // give here the variable name for proportion
alert(total);
//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) && (mrvs == '') && (x == '') && (y == '') && (z == '')) {
g_form.addErrorMessage("Course Completed Date should not be more than 365 days");
return false;
}
}
Thanks,