struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Kiru <kiru.thangav...@gmail.com>
Subject Validating Struts2 fields using JQuery
Date Tue, 28 Apr 2009 14:46:01 GMT
I am using JQuery for validating the fields in my jsp page, created using
Struts 2.1.6. But the jquery validation is
not firing and the form is getting submitted. In the same page I have
created tabs, date picker using JQuery and
they are all working fine. The same JQuery validtion is working fine with
pure html (no struts tag) form. The fields
 that i am trying to validate are inside the jquery tab. Any idea what could
be missing/wrong?

Thanks.

Here is portion of my  .jsp
<%@ taglib prefix="s" uri="/struts-tags"%>
<link type="text/css" href="/abc/css/jquery-ui-1.7.1.custom.css"
rel="stylesheet" />
<script type="text/javascript" src="/abc/js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="
http://dev.jquery.com/view/trunk/plugins/validate/jquery.validate.js
"></script>
<script type="text/javascript"
src="/abc/js/jquery-ui-1.7.1.custom.min.js"></script>
<link rel="stylesheet" type="text/css" href="../css/validate.css" />

<script type="text/javascript">
$(document).ready(function() {
  // validate signup form
   $("#myForm").validate({
   rules: {
    myForm_userId: "required",
   },
   messages: {
    myForm_userId: "Enter user ID",

   },
   // the errorPlacement has to take the table layout into account
    errorPlacement: function(error, element) {
    if ( element.is(":radio") )
     error.appendTo( element.parent().next().next() );
    else if ( element.is(":checkbox") )
     error.appendTo ( element.next() );
    else
     error.appendTo( element.parent().next() );
   },
   // specifying a submitHandler prevents the default submit, good for the
demo
                    /*  submitHandler: function() {
     alert("submitted!");
   }, */
   success: function(label) {
    // set &nbsp; as text for IE
    label.html("&nbsp;").addClass("checked");
   }
  });

 });
 </script>

 <s:form name="myForm" id="myForm" action="myResults"
 namespace="/" method="post" theme="xhtml">

 <table align="center" border="0">
 <table align="center">

     <tr>
      <td colspan="2">
      <s:fielderror cssClass="error">
       <s:param value="userID" />
      </s:fielderror>
      </td>
     </tr>
     <s:textfield name="userID"
      label="%{getText('login.label.userID')}" required="true"
      requiredposition="left" maxlength="10">
      <s:param name="labelstyle" value="%{'boldtext'}" />
     </s:textfield>
    </table>

</s:form>

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