How can I make a checkbox actually mandatory in service catalog?

santrym
Mega Expert

I have a checkbox that says "check this box if you agree to the policy terms...". I made the variable "mandatory", but I can still click "order now" even when the checkbox is not checked. How can I make it so you can only "order now" after the checkbox has been clicked?

1 ACCEPTED SOLUTION

getValue() return the value as string. Try this



function onSubmit() {


    //Type appropriate comment here, and begin script below SpaceIsThePlace


    if (g_form.getValue('PolicyAgreement')=='false') {



  g_form.showFieldMsg('PolicyAgreement', 'You must check the Policy Agreement checkbox', 'error');



  return false;


    }


}


View solution in original post

12 REPLIES 12

Chuck Tomasi
Tera Patron

Hi Michael,



Checkboxes ALWAYS contain a value (true or false). Mandatory means you cannot submit it if the field is null/empty. That's not the case with true/false. So you have two options.



Option a) Change it to a choice list with None, Yes, No and make it mandatory


Option b) Create an onSubmit script that checks for a true value and aborts if not found. Something like below.



function onSubmit() {


    if (!g_form.getValue('my_checkox')) {


              g_form.showFieldMsg('my_checkbox', 'You must check this box', 'error');


              return false;


    }


}


Running that script would be ideal, but I can't get it to work. I can still "Order Now" without checking the box.



In the catalog Item page, I create a new "Catalog Client Script". Applies to "A Catalog Item". Catalog item = "Mobile Device Reimbursement". Type = "onSubmit". Script:



function onSubmit() {


    //Type appropriate comment here, and begin script below SpaceIsThePlace


    if (!g_form.getValue('PolicyAgreement')) {


 


  g_form.showFieldMsg('PolicyAgreement', 'You must check the Policy Agreement checkbox', 'error');


 


  return false;


    }


}





am I doing anything wrong?


getValue() return the value as string. Try this



function onSubmit() {


    //Type appropriate comment here, and begin script below SpaceIsThePlace


    if (g_form.getValue('PolicyAgreement')=='false') {



  g_form.showFieldMsg('PolicyAgreement', 'You must check the Policy Agreement checkbox', 'error');



  return false;


    }


}


That's the magic I was looking for! Thank ya!