You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by rl...@apache.org on 2003/07/30 05:28:55 UTC
cvs commit: jakarta-commons/validator/src/javascript/org/apache/commons/validator/javascript validateIntRange.js
rleland 2003/07/29 20:28:55
Modified: validator/src/javascript/org/apache/commons/validator/javascript
validateIntRange.js
Log:
Bug 21751 report and patch provided by Kurt Post
Allow intRange validation of select-one and radio fields.
In Kurt's words:
In some form combo boxes you might have the combo boxes populated with valid
choices plus one additional choice with a caption something like "Choose one"
and a value 0f "-1". Then when the user attempts to submit the form, you can
look for the value of "-1" and yell at them if they failed to pick something.
Revision Changes Path
1.2 +13 -5 jakarta-commons/validator/src/javascript/org/apache/commons/validator/javascript/validateIntRange.js
Index: validateIntRange.js
===================================================================
RCS file: /home/cvs/jakarta-commons/validator/src/javascript/org/apache/commons/validator/javascript/validateIntRange.js,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- validateIntRange.js 18 May 2003 21:35:37 -0000 1.1
+++ validateIntRange.js 30 Jul 2003 03:28:55 -0000 1.2
@@ -7,13 +7,21 @@
oRange = new intRange();
for (x in oRange) {
var field = form[oRange[x][0]];
-
- if ((field.type == 'text' || field.type == 'textarea') &&
- (field.value.length > 0)) {
-
+ var value = '';
+ if (field.type == 'text' || field.type == 'textarea' ||
+ field.type == 'radio' ) {
+ value = field.value;
+ }
+ if (field.type == 'select-one') {
+ var si = field.selectedIndex;
+ if (si >= 0) {
+ value = field.options[si].value;
+ }
+ }
+ if (value.length > 0) {
var iMin = parseInt(oRange[x][2]("min"));
var iMax = parseInt(oRange[x][2]("max"));
- var iValue = parseInt(field.value);
+ var iValue = parseInt(value);
if (!(iValue >= iMin && iValue <= iMax)) {
if (i == 0) {
focusField = field;
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org