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

I already did that and alerts for the all the state with correct value but still the comment is not mandatory.


If the alerts are firing as intended and as per logic, then only issue will be name of "Catalog variable". Is the name is exactly "comments"?


gowthamanbalu
Tera Contributor

Hi John,


I hope your form's current state value is not 3 when you test this. If so, Client script will not apply to that form, since you are running Onchange client script on the field state.



Here I would suggest to try by removing the below two lines of code in your client script and check once.



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


  return;


  }



Regards,


Gowthaman Balu.