commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Nacho G. Mac Dowell" <>
Subject Bug#: 30872 (It is assigned to struts-dev)
Date Mon, 06 Sep 2004 11:25:48 GMT
NOTE: I have seen this issue has been solved in cvs head (for required
validation). I am posting this anyway as I think it is a more general 
(it grabs all values for an element so you don't have to care what type of
element it is, just its values). Please read on.

The problem with this is the way html handles different input types. 
Some input
types (text, textarea, hidden, password, select-one and file) can only 
single values. Checkboxes, radio buttons (surprising enough) and select-
multiple return multiple values. When performing required validation 
(this also
happens with other validations, some of them even check less types) it 
is not
validating checkboxes and select-multiple and it isn't correctly 
handling radio
buttons. I propose a different way of doing things:

1. First fill the object we use for validation with all the values is 
holding. Textarea, text... will have a single element array and checkbox 
select-multiple may have multiple values.
2. Loop through the validatable elements and then through all their 
values to
perform the actual validation.

We could have textareas, text... to set only a value (not an array), but 
this may lead to confusion and possible inconsistencies.

I beleive that all validations should check all the possible scenarios. 
I don't
see why select-one elements should not be checked for maxlength or 
They are all form-elements regardless of how they are displayed and they 
eventually pass as request parameters.

I am sending a patch with a new javascript function that sets all values on
their respective elements.

validateRequired and validateMinLength is using this new approach as 
well (so
you can se it work).

It is quite difficult to provide tests for this. Solex could probably do 
job for this. It records http activity (as a tunnel) and then can be 
used as
tests. I haven't used it but it sounds good to me. Anyway, this has been 
on IE6 and Mozilla 1.72

Should the javascript functions try to guess correct validation 
definition (for
example: is the field "textField" present before checking if its value 
is not

The new function would be:

  function fillValidateValues(form, oObject) {
    //we'll set a fourth element in the array containing an array of values
    for (fillx in oObject) {
        //variable must be set to something different than x or it gets
confused with caller's x var
        var fillfield = form[oObject[fillx][0]];
        var values = new Array();
        var count = 0;
        if (fillfield.type) {
            if (fillfield.type == 'text' ||
                fillfield.type == 'textarea' ||
                fillfield.type == 'hidden' ||
                fillfield.type == 'file' ||
                fillfield.type == 'select-one' ||
                fillfield.type == 'select-multiple' ||
                fillfield.type == 'password') {
                // get field's value
                if (fillfield.type == "select-one") {
                    var si = fillfield.selectedIndex;
                    //we shouldn't check if si >=0 since select-ones will
always be there when submitting
                    values[count++] = fillfield.options[si].value;
                } else if (fillfield.type == "select-multiple") {
                    //we get all the selected values of this select-multiple
                    //looping through its options array
                    for (i=0; i<fillfield.options.length; i++) {
                        if (fillfield.options[i].selected) {
                            values[count++] = fillfield.options[i].value;
                } else {
                    values[count++] = fillfield.value;
            } else if (fillfield.checked) {
                //it's a single checkbox or single radio
                values[count++] = fillfield.value;
        } else {//it's a nodeList (radio group or checkbox group)
            for (i=0; i<fillfield.length; i++) {
                if (fillfield[i].checked) {
                    values[count++] = fillfield[i].value;
        oObject[fillx][3] = values;
    return oObject;

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message