rleland 2003/10/30 22:09:13
Modified: conf/share validator-rules.xml
Log:
Add required check for single checkbox,
Bug report by Saul Q Yuan
Revision Changes Path
1.44 +18 -13 jakarta-struts/conf/share/validator-rules.xml
Index: validator-rules.xml
===================================================================
RCS file: /home/cvs/jakarta-struts/conf/share/validator-rules.xml,v
retrieving revision 1.43
retrieving revision 1.44
diff -u -r1.43 -r1.44
--- validator-rules.xml 1 Oct 2003 15:43:11 -0000 1.43
+++ validator-rules.xml 31 Oct 2003 06:09:13 -0000 1.44
@@ -39,7 +39,7 @@
errors.range={0} is not in the range {1} through {2}.
errors.creditcard={0} is an invalid credit card number.
errors.email={0} is an invalid e-mail address.
-
+
Note: Starting in Struts 1.2.0 the default javascript definitions have
been consolidated to commons-validator. The default can be overridden
by supplying a <javascript> element with a CDATA section, just as
@@ -71,13 +71,14 @@
for (x in oRequired) {
var field = form[oRequired[x][0]];
-
+
if (field.type == 'text' ||
field.type == 'textarea' ||
field.type == 'file' ||
+ field.type == 'checkbox' ||
field.type == 'select-one' ||
field.type == 'password') {
-
+
var value = '';
// get field's value
if (field.type == "select-one") {
@@ -85,19 +86,23 @@
if (si >= 0) {
value = field.options[si].value;
}
- } else {
+ } else if (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") {
+ } else if (field.type == "select-multiple") {
var numOptions = field.options.length;
lastSelected=-1;
for(loop=numOptions-1;loop>=0;loop--) {
@@ -137,12 +142,12 @@
}
return isValid;
}
-
+
// Trim whitespace from left and right sides of s.
function trim(s) {
return s.replace( /^\s*/, "" ).replace( /\s*$/, "" );
}
-
+
]]>
</javascript>
@@ -194,7 +199,7 @@
depends=""
msg="errors.invalid"/>
-
+
<validator name="mask"
classname="org.apache.struts.validator.FieldChecks"
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]