Getting a black asterick colour and is saving form without checking for change form

raj765_32
Tera Contributor

hi can anyone let me know about the code wrong i have written for the below code:

 

my requirment is that in change form whenever type is normal or expedited i want to display a check box called ' peer review field to show and make mandatory but here iam getting black asterick and form is getting saved without checking the box to ..

Note: changed label from 'peers review to peer review' and given column name as peers review in the code:

code:

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

if (g_form.getValue('type') == "Normal" || g_form.getValue('type') == "Expedited") {
g_form.setMandatory('u_peers_review', true);
g_form.setDisplay('u_peers_review', true);
} else {
g_form.setMandatory('u_peers_review', false);
g_form.setDisplay('u_peers_review', false);
}

if (g_form.getValue('type') == "Normal") {
g_form.setMandatory('u_peers_review', true);
g_form.setDisplay('u_peers_review', true);


} else {
g_form.setMandatory('u_peers_review', false);
g_form.setDisplay('u_peers_review', false);

 

}

}

if (newValue == "Expedited") {
g_form.setMandatory('u_peers_review', true);
g_form.setDisplay('u_peers_review', true);


} else {
g_form.setMandatory('u_peers_review', false);
g_form.setDisplay('u_peers_review', false);


}


if (newValue == "Normal" || newValue == "Expedited") {
g_form.setMandatory('u_peers_review', true);
g_form.setDisplay('u_peers_review', true);
} else {
g_form.setMandatory('u_peers_review', false);
g_form.setDisplay('u_peers_review', false);
}

 

}

1 ACCEPTED SOLUTION

AnveshKumar M
Tera Sage
Tera Sage

Hi @raj765_32,

 

Since this is a checkbox and it only contains a true or false value, it always contains some value (checked: true, un checked: false), which makes mandatory kind of useless.

 

If you want to make the field checked always whenever you make it mandatory, you can add another line of code like the one below.

 

g_form.setValue('u_peers_review', 'true');

 

Otherwise if you want to check whether the field is checked or not on submit you can try using the following onSubmit client script.

 

var checked = g_form.getValue('u_peers_review');

if (!checked) {

        g_form.addErrorMessage('You haven't selected the peer review!');

        return false;

}

 

Please mark my answer helpful, and accept as solution if it helped you solving your issue 😊👍

Thanks,
Anvesh

View solution in original post

1 REPLY 1

AnveshKumar M
Tera Sage
Tera Sage

Hi @raj765_32,

 

Since this is a checkbox and it only contains a true or false value, it always contains some value (checked: true, un checked: false), which makes mandatory kind of useless.

 

If you want to make the field checked always whenever you make it mandatory, you can add another line of code like the one below.

 

g_form.setValue('u_peers_review', 'true');

 

Otherwise if you want to check whether the field is checked or not on submit you can try using the following onSubmit client script.

 

var checked = g_form.getValue('u_peers_review');

if (!checked) {

        g_form.addErrorMessage('You haven't selected the peer review!');

        return false;

}

 

Please mark my answer helpful, and accept as solution if it helped you solving your issue 😊👍

Thanks,
Anvesh