Details
-
Bug
-
Status: Closed
-
Major
-
Resolution: Fixed
-
Nightly Builds
-
None
-
None
-
None
-
Operating System: All
Platform: All
-
33047
Description
When I apply the required validation rule to a single radio button, then
javascript validation passes when it should fail.
Please find herewith enclosed a version that fixes things up in my case:
function validateRequired(form) {
var isValid = true;
var focusField = null;
var i = 0;
var fields = new Array();
var formName = form.getAttributeNode("name");
oRequired = eval('new ' + formName.value + '_required()');
for (x in oRequired) {
var field = form[oRequired[x][0]];
if ((field.type == 'hidden' ||
field.type == 'text' ||
field.type == 'textarea' ||
field.type == 'file' ||
field.type == 'radio' ||
field.type == 'checkbox' ||
field.type == 'select-one' ||
field.type == 'password') &&
field.disabled == false) {
var value = '';
// get field's value
if (field.type == "select-one") {
var si = field.selectedIndex;
if (si >= 0)
} else if (field.type == 'radio' || field.type == 'checkbox') {
if (field.checked)
} else
{ value = field.value; }if (trim(value).length == 0) {
if (i == 0)
{ focusField = field; }fields[i++] = oRequired[x][1];
isValid = false;
}
} else if (field.type == "select-multiple") {
var numOptions = field.options.length;
lastSelected=-1;
for(loop=numOptions-1;loop>=0;loop--) {
if(field.options[loop].selected) { lastSelected = loop; value = field.options[loop].value; break; }
}
if(lastSelected < 0 || trim(value).length == 0) {
if(i == 0) { focusField = field; }
fields[i++] = oRequired[x][1];
isValid=false;
}
} else if ((field.length > 0) && (field[0].type == 'radio' || field
[0].type == 'checkbox')) {
isChecked=-1;
for (loop=0;loop < field.length;loop++) {
if (field[loop].checked)
}
if (isChecked < 0) {
if (i == 0)
fields[i++] = oRequired[x][1];
isValid=false;
}
}
}
if (fields.length > 0)
return isValid;
}