Just made a form with 26 fields. The first six are text/drop/calendar. The middle 19 are radio. The last is a text. ALL fields are set to 1, required. But, when I test the form only the first six and last text field actually require you to fill them in. You can skip the radio buttons and it doesn't kick you back.
Yes, this is a known issue. I have provided a solution for a few people who have asked for it but it requires editing your form file. Let me know if you want to have this additional code.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
You can put this function right above the "validateField" function which
appears near the top of your form.html file.
function validateCheckBox(fieldId, fieldBoxId, fieldType, mysize, minrequired) {
alert('Validating CheckBox');
ii=0;
fieldBox = document.getElementById(fieldBoxId);
if(minrequired > 0) {
alert('CheckBox is required');
<!-- Loop through each checkbox to see if any are checked -->
for( i=1; i<=mysize; i++) {
myfieldId = fieldId+"_option_"+i;
fieldObj = document.getElementById(myfieldId);
if(fieldObj.checked == 1) {
alert('CheckBox is checked');
<!-- Keep track of the number of checkboxes checked -->
ii++;
myfieldId = fieldId+"_option_"+i;
fieldObj = document.getElementById(myfieldId);
fieldObj.setAttribute("class","mainForm");
fieldObj.setAttribute("className","mainForm");
<!-- If not checked return box to highlighted state -->
} else {
fieldObj.setAttribute("class","mainFormError");
fieldObj.setAttribute("className","mainFormError");
}
}
if(ii == minrequired) {
for( i=1; i<=mysize; i++) {
<!-- Return all checkboxes to non-highlighted state -->
myfieldId = fieldId+"_option_"+i;
fieldObj = document.getElementById(myfieldId);
fieldObj.setAttribute("class","mainForm");
fieldObj.setAttribute("className","mainForm");
}
return true;
}
fieldObj.focus();
return false;
}
}
Put the code below in the same area as the rest of the "if(validateField"
checks appear. This is in a function called "validatePageN()" where N
can be any number usually represents the number of pages in your form.
The "if(validateCheckBox" piece really only needs to be in sections
that have check boxes. The numbers at the end of the check "2,1" in
the example below represent the following:
2= the number of check boxes associated with a particular set of options.
1= the number of selections required to be checked before submit is
successful.
Example: You have a question that requires a yes or no answer. The
question is followed by two check buttons/boxes, one for "yes" the other
for "no". Obviously an answer is required so like the example below "2,1"
there are 2 check boxes/buttons and 1 is required.
Should work either way. If you try it and it does not work maybe I have just mis-placed my final version. Let me know. It also looks like I left some debug "alerts" in place. They can be commented out.
Note the code where it looks at whether an entry is "checked" or not, not whether it has a particular value.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Also, is there a way to create a new field that requires the user to enter a matching piece of text? In my case I want the user to enter a specific tail number of an aircraft. I have about 100+ tail numbers. I don't want a drop down because I want to make sure they are entering their tail number and not just picking from a list. I want them to enter a valid tail number from a list that I have in the code. They aren't too tech savvy so I'm not worried about them looking through the code to find a number.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Just made a form with 26 fields. The first six are text/drop/calendar. The middle 19 are radio. The last is a text. ALL fields are set to 1, required. But, when I test the form only the first six and last text field actually require you to fill them in. You can skip the radio buttons and it doesn't kick you back.
Is this a known bug?
Test form:
http://www.buckeyetechguy.com/form/form.html
Thanks for any help in advance!
C
Yes, this is a known issue. I have provided a solution for a few people who have asked for it but it requires editing your form file. Let me know if you want to have this additional code.
YES! Please give me the code! :)
You can put this function right above the "validateField" function which
appears near the top of your form.html file.
function validateCheckBox(fieldId, fieldBoxId, fieldType, mysize, minrequired) {
alert('Validating CheckBox');
ii=0;
fieldBox = document.getElementById(fieldBoxId);
if(minrequired > 0) {
alert('CheckBox is required');
<!-- Loop through each checkbox to see if any are checked -->
for( i=1; i<=mysize; i++) {
myfieldId = fieldId+"_option_"+i;
fieldObj = document.getElementById(myfieldId);
if(fieldObj.checked == 1) {
alert('CheckBox is checked');
<!-- Keep track of the number of checkboxes checked -->
ii++;
myfieldId = fieldId+"_option_"+i;
fieldObj = document.getElementById(myfieldId);
fieldObj.setAttribute("class","mainForm");
fieldObj.setAttribute("className","mainForm");
<!-- If not checked return box to highlighted state -->
} else {
fieldObj.setAttribute("class","mainFormError");
fieldObj.setAttribute("className","mainFormError");
}
}
if(ii == minrequired) {
for( i=1; i<=mysize; i++) {
<!-- Return all checkboxes to non-highlighted state -->
myfieldId = fieldId+"_option_"+i;
fieldObj = document.getElementById(myfieldId);
fieldObj.setAttribute("class","mainForm");
fieldObj.setAttribute("className","mainForm");
}
return true;
}
fieldObj.focus();
return false;
}
}
Put the code below in the same area as the rest of the "if(validateField"
checks appear. This is in a function called "validatePageN()" where N
can be any number usually represents the number of pages in your form.
The "if(validateCheckBox" piece really only needs to be in sections
that have check boxes. The numbers at the end of the check "2,1" in
the example below represent the following:
2= the number of check boxes associated with a particular set of options.
1= the number of selections required to be checked before submit is
successful.
Example: You have a question that requires a yes or no answer. The
question is followed by two check buttons/boxes, one for "yes" the other
for "no". Obviously an answer is required so like the example below "2,1"
there are 2 check boxes/buttons and 1 is required.
if(validateCheckBox'field_8','fieldBox_8','checkbox',2,1) == false)
retVal=false;
TNTEverett,
It looks like this code is for Checkboxes but I'm using Radios.
Should work either way. If you try it and it does not work maybe I have just mis-placed my final version. Let me know. It also looks like I left some debug "alerts" in place. They can be commented out.
Note the code where it looks at whether an entry is "checked" or not, not whether it has a particular value.
TNT - Can't figure out what you mean by "left some debug "alerts" in place. I can't figure out what to comment out....
Strike that, I figured out the alerts.
Also, is there a way to create a new field that requires the user to enter a matching piece of text? In my case I want the user to enter a specific tail number of an aircraft. I have about 100+ tail numbers. I don't want a drop down because I want to make sure they are entering their tail number and not just picking from a list. I want them to enter a valid tail number from a list that I have in the code. They aren't too tech savvy so I'm not worried about them looking through the code to find a number.