commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rlel...@apache.org
Subject cvs commit: jakarta-commons/validator/src/javascript/org/apache/commons/validator/javascript validateRequired.js
Date Wed, 24 Sep 2003 03:44:10 GMT
rleland     2003/09/23 20:44:10

  Modified:    validator/src/javascript/org/apache/commons/validator/javascript
                        validateRequired.js
  Log:
  Bug#:	18993, and Bug#:	11520
  Patches provided by  Greg Ludington,  Steve Stair, Saul Q Yuan
  Add ability of required to handle checkboxes, radio,select-one,
  and select-multiple field types.
  
  Revision  Changes    Path
  1.5       +19 -1     jakarta-commons/validator/src/javascript/org/apache/commons/validator/javascript/validateRequired.js
  
  Index: validateRequired.js
  ===================================================================
  RCS file: /home/cvs/jakarta-commons/validator/src/javascript/org/apache/commons/validator/javascript/validateRequired.js,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- validateRequired.js	9 Sep 2003 06:19:57 -0000	1.4
  +++ validateRequired.js	24 Sep 2003 03:44:10 -0000	1.5
  @@ -34,11 +34,29 @@
                       fields[i++] = oRequired[x][1];
                       isValid = false;
                   }
  -            } else if ((field.length > 0) && (field[0].type == 'radio')) {
  +            } 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) {
  
  
  

Mime
View raw message