struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Chetan Pandey" <cpan...@BLUEsingapore.com>
Subject Client Side Validation
Date Wed, 02 Aug 2006 01:54:56 GMT
Hi All:

 

I am trying to do Client-Side Validation for my JSP Form:

 

<html:javascript formName="AttendeeDetailsForm"/>

 

<html:errors/>

 

 

 

<html:form action="/addAttendeeDetails">

.

.

.

.

</html:form>

 

 

But the problem is I only see Server Side Validations no Client Side
Validations.

 

This is the Validator I am using which I copied from the Net:

 

/***************************************************************************
********************/

<validator name="required"

            classname="org.apache.struts.validator.FieldChecks"

               method="validateRequired"

         methodParams="java.lang.Object,

                       org.apache.commons.validator.ValidatorAction,

                       org.apache.commons.validator.Field,

                       org.apache.struts.action.ActionMessages,

                       org.apache.commons.validator.Validator,

                       javax.servlet.http.HttpServletRequest"

                  msg="errors.required">

        <javascript><![CDATA[

            function validateRequired(form) {

                var isValid = true;

                var focusField = null;

                var i = 0;

                var fields = new Array();

                oRequired = new required();

                for (x in oRequired) {

                  var field = form[oRequired[x][0]];

                  

                    if (field.type == 'text' ||

                        field.type == 'textarea' ||

                        field.type == 'file' ||

                        field.type == 'select-one' ||

                        field.type == 'radio' ||

                        field.type == 'password') {

                        

                        var value = '';

                                    // get field's value

                                    if (field.type == "select-one") {

                                          var si = field.selectedIndex;

                                          if (si >= 0) {

                                                value =
field.options[si].value;

                                          }

                                    } else {

                                          value = field.value;

                                    }

                        

                        if (trim(value).length == 0) {

                        

                              if (i == 0) {

                                  focusField = field;

                              }

                              fields[i++] = oRequired[x][1];

                              isValid = false;

                        }

                    }

                }

                if (fields.length > 0) {

                   focusField.focus();

                   alert(fields.join('\n'));

                }

                return isValid;

            }

            

            // Trim whitespace from left and right sides of s.

            function trim(s) {

                return s.replace( /^\s*/, "" ).replace( /\s*$/, "" );

            }

            

            ]]>

         </javascript>           

    </validator>

 

/***************************************************/

 

 

Does anyone have any Idea why I don't see Client Side Validation


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message