The CreatorCon Call for Content is officially open! Get started here.

Make field visible when another field changes

BiancaK
Tera Expert

Hi Developers

I am trying to achieve the below. When a user changes the Forecasted date then the fields "Reason for change, Category and Sub category" should become visible on the form and mandatory. I was able to configure the requirement to make the field mandatory when user changes the Forecasted date. But how can I hide these fields from the form initially?

BiancaK_0-1722548381038.png

 

Please the code below:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {  


  if (isLoading || newValue === '') {  


  if(g_form.isNewRecord() && newValue!=''){

g_form.setVisible('u_reason_for_change', false);
g_form.setMandatory('u_reason_for_change', false);


}
  return;  

  }  

  if(oldValue != newValue)  

  {  

  g_form.setValue('u_reason_for_change', true);
  g_form.setMandatory('u_reason_for_change', true);


  }  

  else  

  {  

  g_form.setVisible('u_reason_for_change', false);
  g_form.setMandatory('u_reason_for_change', false);


  }  


}  
1 ACCEPTED SOLUTION

@BiancaK Try writing a ui policy to hide all the field initially. Then update your if condition for above code share by me as 

if (oldValue != '' && oldValue != newValue)

 

…………………………………………..
Mark it helpful 👍and Accept Solution !! If this helps you to understand.

View solution in original post

15 REPLIES 15

Bhagyashri123
Tera Contributor

Hi @BiancaK !

hope you are doing well . To achieve this you have two ways UI policy and Client Script.
with UI policy you simply need to set condition and  enable the visibility
Condition can be the forecasted date is not empty.
Client Script: you were asking about from where you can set its visibility false:

function onChange(control, oldValue, newValue, isLoading, isTemplate) {  
  if (isLoading || newValue === '')
{  
  if(g_form.isNewRecord())
{
      g_form.setVisible('u_reason_for_change'false);
      g_form.setVisible('u_category', false);

       g_form.setVisible('u_sub_category', false);
  

}
 

      return;  

}

  g_form.setVisible('u_reason_for_change'true);
  g_form.setMandatory('u_reason_for_change', true);
  g_form.setVisible('u_category', true);
  g_form.setMandatory('u_category', true);
  g_form.setVisible('u_sub_category', true);
  g_form.setMandatory('u_sub_category', true);

}