Onchange client script when a field changes

Deepthi13
Tera Expert

Hi team,

(i have couple of other validations so i am writing client script instead of ui policy)

i am trying below script on onchange on emptype field, it is working fine for both if condition. 

  1. But when i change value to "employee" i am getting alert inside 1st if condition, and form looks like below
  2. When I change to “consultant” I am getting alert in second if condition but it does not hide the fields still remains same on form please suggest. 

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var emptype = g_form.getValue('employement_type');
if(emptype=='employee'){
alert('onchange employee'+emptype);
g_form.setDisplay('candidate_id',true);
g_form.setDisplay('u_employee_id',true);
g_form.setMandatory('candidate_id',true);
g_form.setMandatory('u_employee_id',true);
}

if(emptype=='consultant'){
alert('onchange consultant'+emptype);
g_form.setDisplay('candidate_id',false);
g_form.setDisplay('u_employee_id',false);
g_form.setMandatory('candidate_id',false);
g_form.setMandatory('u_employee_id',false);
}
//Type appropriate comment here, and begin script below

}

 

1 ACCEPTED SOLUTION

Just add it like this to simplify

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
  return;
}

g_form.clearValue('candidate_id',true);
g_form.clearValue('u_employee_id',true);

var emptype = g_form.getValue('employement_type');
if(emptype=='employee'){
alert('onchange employee'+emptype);
g_form.setDisplay('candidate_id',true);
g_form.setDisplay('u_employee_id',true);
g_form.setMandatory('candidate_id',true);
g_form.setMandatory('u_employee_id',true);
}

if(emptype=='consultant' || emptype=='none'){
alert('onchange consultant'+emptype);
g_form.setMandatory('candidate_id',false);
g_form.setMandatory('u_employee_id',false);
g_form.setDisplay('candidate_id',false);
g_form.setDisplay('u_employee_id',false);
}

}

View solution in original post

13 REPLIES 13

Alikutty A
Tera Sage

Hi,

Please change the order and try

if(emptype=='consultant'){
alert('onchange consultant'+emptype);
g_form.setMandatory('candidate_id',false);
g_form.setMandatory('u_employee_id',false);
g_form.setDisplay('candidate_id',false);
g_form.setDisplay('u_employee_id',false);

}

ya, thanks. and some more doubt, now my requirment is when (candidate_id and u_employee_id) both populated, if any one variable is filled the other should not be mandatory any more.

but see below screen shot when i enter candid still both are mandatory

find_real_file.png

so first i am tryin othet onchange on candidate_id variable as below script, but both alerts are not coming, pls suggest

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var candid = g_form.getValue('candidate_id');
if(candid==''){
alert('onchange candid is empty'+candid);
g_form.setMandatory('u_employee_id',true);
}

if(candid!=''){
alert('onchange candid is not empty'+emptype);
g_form.setMandatory('u_employee_id',false);
}
//Type appropriate comment here, and begin script below

}

Try this

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
var candid = g_form.getValue('candidate_id');
if(candid==''){
alert('onchange candid is empty'+candid);
g_form.setMandatory('u_employee_id',true);
}

if(candid!=''){
alert('onchange candid is not empty');
g_form.setMandatory('u_employee_id',false);
}
//Type appropriate comment here, and begin script below

}

worked now 🙂  i need to do same logic for u_employee_id also can i write one more onchange on u_employee_id with below code...

function onChange(control, oldValue, newValue, isLoading) {
if (isLoading) {
return;
}
var empid = g_form.getValue('u_employee_id');
if(empid==''){
alert('onchange empid is empty'+empid);
g_form.setMandatory('candidate_id',true);
}


if(candid!=''){
alert('onchange empid is not empty');
g_form.setMandatory('candidate_id',false);
}
//Type appropriate comment here, and begin script below

}