onLoad() function call within onChange() - Client script

Anish Reghu
Kilo Sage
Kilo Sage

Dear experts,

Is the following possible in one single onChange client script? I understand, we can have the onLoad as a separate client script.

Task 1 - Validate some values of a checkbox to be true or false on load of a form and apply logic.

Task 2 - proceed next into onChange validation and logic.

Example:

function onLoad()

{

//executes first

}

function onChange(parameters)

{

//executes next

}

 

Regards,

Anish

1 ACCEPTED SOLUTION

Saiganeshraja
Kilo Sage
Kilo Sage
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   //If the form is loading or the new value of the changing field is empty exit the script
   if (isLoading || newValue == '') {

/// Write your onload logic here
      return;    }
On change logic under it .

Mark correct and helpful.

View solution in original post

5 REPLIES 5

Saiganeshraja
Kilo Sage
Kilo Sage
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   //If the form is loading or the new value of the changing field is empty exit the script
   if (isLoading || newValue == '') {

/// Write your onload logic here
      return;    }
On change logic under it .

Mark correct and helpful.

Use Case:

 

Agree, we are validating a logic while the form is loading, but what if the validation is to happen after the form has loaded and before the onChange is to be validated?

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   //If the form is loading or the new value of the changing field is empty exit the script
   
if (isLoading || newValue == '') {
      return;    }

You might propose:

if(isLoading)
{
//apply Logic;

if(g_form.getValue('field_name') == 'true')
//do this;
}

//Continue with onChange logic.

doesn't work!

Regards,
Anish

Hi Anish,

Try this.

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   //If the form is loading or the new value of the changing field is empty exit the script
   
   You might propose:

   if(isLoading)
   {
     //apply Logic;
     if(g_form.getValue('field_name') == 'true')
         //do this;
   }
if(!isLoading)
   {
    //Continue with onChange logic.

   }

  
Please hit like and mark my response as correct if that helps
Regards,
Musab

Hi Musab, thanks! but won't really make a difference,

since,

I am trying to make this part work:

if(isLoading)
   {
     //apply Logic;
     if(g_form.getValue('field_name') == 'true')
         //do this;
   }

This one is already working:

//Continue with onChange logic.

So, doing a if(!isLoading) technically, doesn't make a difference.

I repeat, what is needed is:
- Logic to run after the form is loaded
- and before proceeding into the onChange logic.

Regards,
Anish