Hide and make visible a field on condition

arohi
Kilo Expert

Hi,

I need to hide a field 'Reason for updating expected remediation date' on form when it loads.

for this i wrote this onload script

g_form.setVisible('u_reason_for_updated_remediation_date', false);

this is working fine.

and there is another field 'Expected remediation date' which will take value for the first time. but later if the date is updated, then this 'reason' field should be visible and should be mandatory. for this i wrote onchange script

if (oldValue != newValue){

            g_form.setVisible('u_reason_for_updated_remediation_date', true);

  g_form.setMandatory('u_reason_for_updated_remediation_date', true);

}

but this is not working as expected it is visible and mandatory when first time date field is being filled. i don't want this, i want if second time the date field is being updated that time 'reason' field should be visible.

For this i tried this script also, still not working.

var previousValue = g_form.getValue('u_expected_remediation_date');

{

  if(previousValue != null && previousValue != newValue) {

            g_form.setVisible('u_reason_for_updated_remediation_date', true);

  g_form.setMandatory('u_reason_for_updated_remediation_date', true);

}

Please suggest.

4 REPLIES 4

Manoj Kumar16
Giga Guru

You can use- g_form.isNewRecord()


Hi,



You can try this, if again filed then u want to make field mandatory.



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


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


  return;


        }


    g_form.setVisible('u_reason_for_updated_remediation_date', true);


  g_form.setMandatory('u_reason_for_updated_remediation_date', true);


    }



Hope it helps,



Thanks,


Apurva Sharma


dasthu1
Kilo Expert

Hi Arohi,



remove the brace like se as below,


var previousValue = g_form.getValue('u_expected_remediation_date');



  if(previousValue != null && previousValue != newValue) {


            g_form.setVisible('u_reason_for_updated_remediation_date', true);


  g_form.setMandatory('u_reason_for_updated_remediation_date', true);


}



Please Mark as Correct or Hit Like or Mark as helpful if Helps


arohi
Kilo Expert

Finally this one helped. Thank you all for your suggestions.



if (oldValue == null)


  {


  g_form.setVisible('u_reason_for_updated_remediation_date', false);


  }


  else if (oldValue != newValue){


          g_form.setVisible('u_reason_for_updated_remediation_date', true);


  g_form.setMandatory('u_reason_for_updated_remediation_date', true);


      }  


  else{}


}