You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by bu...@apache.org on 2005/01/11 16:42:05 UTC
DO NOT REPLY [Bug 33047] New: -
validateRequired on a single radio button
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG�
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=33047>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND�
INSERTED IN THE BUG DATABASE.
http://issues.apache.org/bugzilla/show_bug.cgi?id=33047
Summary: validateRequired on a single radio button
Product: Commons
Version: 1.4 Final
Platform: PC
OS/Version: All
Status: NEW
Severity: normal
Priority: P2
Component: Validator
AssignedTo: commons-dev@jakarta.apache.org
ReportedBy: fabio.grassi@ggsinformatica.it
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) {
value = field.options[si].value;
}
} else if (field.type == 'radio' || field.type == 'checkbox') {
if (field.checked) {
value = field.value;
}
} 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) {
isChecked=loop;
break; // only one needs to be checked
}
}
if (isChecked < 0) {
if (i == 0) {
focusField = field[0];
}
fields[i++] = oRequired[x][1];
isValid=false;
}
}
}
if (fields.length > 0) {
focusField.focus();
alert(fields.join('\n'));
}
return isValid;
}
--
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org