Catalog client script function available in other catalog client scripts in the same catalog item

Michael Culhan1
Kilo Sage

I have a catalog item where I have to validate that 16 fields contain only numbers.  Validation should be done onChange for each of the 16 fields.  I can create a global UI script and call it from the 16 onChange scripts, however as I understand this global script will load for all catalog items.  Is there some way to define a function that is only available to other  catalog client scripts in the same catalog item?  I tried defining it in an onLoad script, but this didn't work.

2 ACCEPTED SOLUTIONS

AnirudhKumar
Mega Sage
Mega Sage

This is an age-old problem. You will have to write a client script for each field unfortunately.

I can propose an alternative...

Use the OOB Regex at the field level.

find_real_file.png

View solution in original post

larstange
Mega Sage

Hi

You can easy create a "global" function within the catalog item by defining a function in an onload script. It needs to be declared outside the default onLoad function like this:

 

functionName = function() { //This function can be called from other onChange client scripts
   //Add your function code here
};

View solution in original post

2 REPLIES 2

AnirudhKumar
Mega Sage
Mega Sage

This is an age-old problem. You will have to write a client script for each field unfortunately.

I can propose an alternative...

Use the OOB Regex at the field level.

find_real_file.png

larstange
Mega Sage

Hi

You can easy create a "global" function within the catalog item by defining a function in an onload script. It needs to be declared outside the default onLoad function like this:

 

functionName = function() { //This function can be called from other onChange client scripts
   //Add your function code here
};