onSubmit client script to make boolean field mandatory

davilu
Mega Sage

I have a true/false field on a form that I want to make mandatory.  After reading through some posts, I came across this one, which recommended writing the following onSubmit client script:

function onSubmit() {
var value = g_form.getValue('searched_resources');
if(!value){
alert('Please check the checkbox before submitting a new HR Request');
return false;
}
}

I have UI Type set to All, but I can still submit this form without checking the checkbox.  What am i missing?  Thanks!

1 ACCEPTED SOLUTION

vinothkumar
Tera Guru

Can you try something as below and it will work

 

function onSubmit() {
//Type appropriate comment here, and begin script below SpaceIsThePlace
if (g_form.getValue('searched_resources')=='false') {

alert('Please check the checkbox before submitting a new HR Request');

return false;
}
}

View solution in original post

7 REPLIES 7

ahh so close, thanks!!

SanjivMeher
Kilo Patron
Kilo Patron

It should check for both null and false. So the script should be 

function onSubmit() {
//Type appropriate comment here, and begin script below SpaceIsThePlace
if (g_form.getValue('searched_resources')=='false' || g_form.getValue('searched_resources')=='') {

alert('Please check the checkbox before submitting a new HR Request');
return false;
}

}

 


Please mark this response as correct or helpful if it assisted you with your question.

poyntzj
Kilo Sage

Make the field mandatory so it needs a value

Then have an onChange client script so if the new value is not true you set the value to 

if (newValue != true) {

g_form.setValue(<variable>,'');

}

The check makes the variable blank instead of clearing and then the mandatory is enforced