setMandatory is not working in my onchange script

John Gomolon
Giga Contributor

This my onChange Client script that makes the comment field mandatory if correct state is selected.

My problem is that if i select state(1,2,4)   the comment field will become mandatory and I select state(3), it wont become mandatory.

Could you help me on this, i don't know the root cause of this script because they are in the same IF.

Here is my code:

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

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

  return;

  }

var state = newValue;

if(state == '1' || state == '2' || state == '3' || state == '4'){

    form.setMandatory('comments', true);

  }

}

thanks,

12 REPLIES 12

Hi John,



That means there's no problem with this particular script. Please check other client scripts that might be working on comments field. Try disabling all other scripts (I know, its drastic) and run only this script. If even that doesn't work, I suggest raising an incident for HI.



Thanks,


Mandar


Harish KM
Kilo Patron
Kilo Patron

it is g_form.setMandatory('comments', true);


Regards
Harish

ramireddy
Mega Guru

Apply IF condition for only 1,2,4. and also change "form" to "g_form".




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


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


  return;


  }


var state = newValue;


if(state == '1' || state == '2' || state == '4'){


    g_form.setMandatory('comments', true);


  }


else


g_form.setMandatory('comments', false);


}


Hi Ram,



Already did that but not working!



thanks


I tried an example. Its working. You need to start debugging. Please place few "alert" statements and check whether this event is firing or not, then whats the value is passing as newValue? I placed few alerts. Please let us know what are you getting as alerts.



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


alert("In onchange event:newValue is" + newValue);


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


  return;


  }


var state = newValue;


if(state == '1' || state == '2' || state == '4'){


  alert("to set mandatory as true");


    g_form.setMandatory('comments', true);


  }


else


{


alert("to set mandatory as false");


g_form.setMandatory('comments', false);


}


}