Validation Script for Multi-Row variable set

Ankit18
Mega Contributor

Hi,

I need to add the validation script on multi-row variable set which will validate the value in the single line text and restrict user to add the row in MRVS. I tried below Catalog Client Script but it is not working 

Applies to - A variable set

Type = OnSubmit

function onSubmit() {

var msg = 'You cannot enter a single or double quote or a backslash';
var mrvs = g_form.getValue('IO:0c5fb747db2b8c102cb804c2ca9619d5');
//var mrvs = JSON.parse(g_form.getValue('test_mrvs'));

for(var i=0;i<mrvs.length;i++)
{

if (!isValid(mrvs[i].test_variable)) {

g_form.addErrorMessage(msg);

return false;
}
}

}

function isValid(text) {
var IsValidChar = true;

if (text == null) return;
if (text.indexOf('"') > -1 || text.indexOf('\\') > -1 || text.indexOf('\'') > -1) {
IsValidChar = false;
}

return IsValidChar;
}

 

8 REPLIES 8

sachin_namjoshi
Kilo Patron
Kilo Patron

Hi Sachin,

 

This post does not have the use case I am trying to achieve. I want to put the validation before the user will add the row in the MRVS and it seems The script I used is not working on the Add button on the popup. I want to restrict user to add the row if the data is not valid. I know we can do it onSubmit script of catalog but for the better user experience, I am trying to do it while the user is adding the rows. 

 

Thanks,

Ankit

art_jones
Kilo Sage

I usually do this with an onChange script, as opposed to an onSubmit. The onChange runs on the variable you need to validate, on the variable set not the item.

 

 

I tried with the onChange as well but it seems that even there is an error in the MRVS pop-up but it still allows you to click on the Add button and add rows. It is not restricting user to add rows if there are any error on the popup.