Make any one of the Order Guide choices Mandatory

amacqueen
Mega Guru

We have an order guide that contains a series of variables for user information and then lists a series of accounts the user can request.

As things stand if the user doesn't choose an account and then selects the 'Choose Options' button it falls over so I need to find a way to force the user to select at least one of these accounts before they can select 'Choose Options'.

Any input gratefully received.

1 ACCEPTED SOLUTION

Your 'onSubmit' client script should be against the catalog item (the actual item/order guide), not on the Order Guide table.   Use the 'Client Scripts' related list at the bottom of your order guide form to add the necessary catalog client script.   If the related list isn't there, you'll need to personalize related lists to add it.


View solution in original post

14 REPLIES 14

Trouble is there are multiple accounts/order items and if none are selected I need to force the user to select one.


Mark, thanks for reading. I've tried   having a go at your suggestion by creating an onSubmit client script on the Order Guide table as below and it doesn't work, any thoughts?



function onSubmit(){


      //Set the mandatory checkbox variable names and total mandatory count here


      var mandatoryVars = 'vision,u_other_amendments,trf,tms,pkms,opus,e400,coda,adaccount,ace';


      var mandatoryCount = 1;


     


      var passed = forceMandatoryCheckboxes(mandatoryVars, mandatoryCount);


      if(!passed){


              //Abort the submit


              alert('You must select at least ' + mandatoryCount + ' options.');


              return false;


      }


}




function forceMandatoryCheckboxes(mandatory, count){


      //Split the mandatory variable names into an array


      mandatory = mandatory.split(',');


      var answer = false;


      var varFound = false;


      var numTrue = 0;


      //Check each variable in the array


      for(x=0;x<mandatory.length;x++){


              //Check to see if variable exists


              if(g_form.getControl(mandatory[x])){


                      varFound = true;


                      //Check to see if variable is set to 'true'


                      if(g_form.getValue(mandatory[x]) == 'true'){


                              numTrue ++;


                              //Exit the loop if we have reached required number of 'true'


                              if(numTrue >= count){


                                      answer = true;


                                      break;


                              }


                      }


              }


      }


      //If we didn't find any of the variables allow the submit


      if(varFound == false){


              answer = true;


      }


      //Return true or false


      return answer;


}


Your 'onSubmit' client script should be against the catalog item (the actual item/order guide), not on the Order Guide table.   Use the 'Client Scripts' related list at the bottom of your order guide form to add the necessary catalog client script.   If the related list isn't there, you'll need to personalize related lists to add it.


Perfect Mark, thank you so much.