Issues with Select Box default value/mandatory attribute

craigzeleznick
Kilo Contributor

I currently have a select box and for the default value I have it as "-- Please Select --" but I also need this field to be mandatory field. When testing the red asterisk is there but if the field is left blank and the person submits the form anyway it still allows them to submit without filling in the mandatory fields.

Can someone point me in the right direction on how to fix this issue?

1 ACCEPTED SOLUTION

Hey Craig,



you can add an onSubmit client script:




function onSubmit() {  


  //Type appropriate comment here, and begin script below  


  var v = g_form.getValue('select');//the name of your field  


  if(v == '-- Please Select --') {  


  alert('You must choose an option in the select field');  


  return false;  


  }  


}



NOTE -


In place of "--Please Select --" put the value of that choice.


View solution in original post

17 REPLIES 17

So a couple of things:


1.       var v = g_form.getValue('Type of Request');//the name of your field


This is not the name of your field, but rather its label; the name is salesforce_type.


So: var v = g_form.getValue('salesforce_type');//the name of your field



2. null is fine



Please change the line and let me know how it works for you.


Harel


This worked, thank you so much!



Thank you,



Craig Zeleznick


Good.


Feel free to mark answers as correct to get them out of the unanswered queue.


And helpful, if anything was helpful



harel


Vladi1
Kilo Guru

Can you use "include none" option? Your requester can submit request without selecting anything, because you defined a value. So, for the SNOW it is not blank field. If you use any script make sure it works on Service Portal (if it is enabled in your system)


Screen Shot 2017-03-22 at 09.33.45.png