更新模式jquery框不起作用



我有一个带有验证及其工作的createjquery模态框。但对于我的更新jquery模态框,它不起作用。bvalid没有运行验证,因为我已经尝试在取消按钮中提交表单,并且它有效。让我给你们看看密码。

$(function() {
      var username = $( "#username" ),
      email = $( "#email" ),
      password = $( "#password" ),
      accountexpired = $( "#account_expired" ),
      allFields = $( [] ).add( username ).add( email ).add( password ).add( accountexpired ),
      tips = $( ".validateTips" );
    function updateTips( t ) {
      tips
        .text( t )
        .addClass( "ui-state-highlight" );
      setTimeout(function() {
        tips.removeClass( "ui-state-highlight", 1500 );
      }, 500 );
    }
    function checkLength( o, n, min, max ) {
      if ( o.val().length > max || o.val().length < min ) {
        o.addClass( "ui-state-error" );
        updateTips( "Length of " + n + " must be between " +
          min + " and " + max + "." );
        return false;
      } else {
        return true;
      }
    }
    function checkRegexp( o, regexp, n ) {
      if ( !( regexp.test( o.val() ) ) ) {
        o.addClass( "ui-state-error" );
        updateTips( n );
        return false;
      } else {
        return true;
      }
    }
    $( "#edit1" ).dialog({
      autoOpen: false,
      height: 700,
      width: 500,
      modal: true,
      buttons: {
        "Update": function() {
             var bValid = true;
             allFields.removeClass( "ui-state-error" );
              bValid = bValid && checkLength( username, "Length of username must be between 3 and 16. Username may consist of a-z, 0-9, underscores, begin with a letter. ", 3, 16 );
              bValid = bValid && checkLength( email, "Length of email must be between 6 and 80. eg. ui@mail.com", 6, 80 );
              bValid = bValid && checkLength( password, "Length of password must be between 5 and 16. Password field only allow : a-z 0-9", 5, 16 );
              bValid = bValid && checkRegexp( username, /^[a-z]([0-9a-z_])+$/i, "Username may consist of a-z, 0-9, underscores, begin with a letter." );
              bValid = bValid && checkRegexp( email, /^((([a-z]|d|[!#$%&'*+-/=?^_`{|}~]|[u00A0-uD7FFuF900-uFDCFuFDF0-uFFEF])+(.([a-z]|d|[!#$%&'*+-/=?^_`{|}~]|[u00A0-uD7FFuF900-uFDCFuFDF0-uFFEF])+)*)|((x22)((((x20|x09)*(x0dx0a))?(x20|x09)+)?(([x01-x08x0bx0cx0e-x1fx7f]|x21|[x23-x5b]|[x5d-x7e]|[u00A0-uD7FFuF900-uFDCFuFDF0-uFFEF])|(\([x01-x09x0bx0cx0d-x7f]|[u00A0-uD7FFuF900-uFDCFuFDF0-uFFEF]))))*(((x20|x09)*(x0dx0a))?(x20|x09)+)?(x22)))@((([a-z]|d|[u00A0-uD7FFuF900-uFDCFuFDF0-uFFEF])|(([a-z]|d|[u00A0-uD7FFuF900-uFDCFuFDF0-uFFEF])([a-z]|d|-|.|_|~|[u00A0-uD7FFuF900-uFDCFuFDF0-uFFEF])*([a-z]|d|[u00A0-uD7FFuF900-uFDCFuFDF0-uFFEF]))).)+(([a-z]|[u00A0-uD7FFuF900-uFDCFuFDF0-uFFEF])|(([a-z]|[u00A0-uD7FFuF900-uFDCFuFDF0-uFFEF])([a-z]|d|-|.|_|~|[u00A0-uD7FFuF900-uFDCFuFDF0-uFFEF])*([a-z]|[u00A0-uD7FFuF900-uFDCFuFDF0-uFFEF]))).?$/i, "eg. ui@jquery.com" );
              bValid = bValid && checkRegexp( password, /^([0-9a-zA-Z])+$/, "Password field only allow : a-z 0-9" );

          if ( bvalid ) {
              $( this ).dialog( "close" );
              $('#editUser').submit();
          }
        },
        Cancel: function() {
          $( this ).dialog( "close" );
        }
      }
    });

至于html:

<%--Update user box --%>
            <div id="edit1" title="Update user">
                  <form id="editUser" method="post" name="editUser">
                      <p class="validateTips"><g:message code="default.error.requiredforms.message" />.</p>
                        <g:each in="${Query1}">
                <table id="editpage" style="border-collapse: collapse;">
                    <tr>
                        <td><label for="username"><g:message code="default.searchcustomer.username.message" />:</label></td>
                        <td><input type="hidden" name="username" id="username"
                            style="border: 1px solid black" value="${it.username}" /><label>${it.username}</label></td>
                    </tr>
                    <tr>
                        <td style="white-space: nowrap"><label for="account_expired"><g:message code="default.searchcustomer.accexpired.message" />:</label></td>
                        <td style="text-align: left"><input type="radio"
                            name="account_expired" id="account_expired" value="${true}"
                            ${it.account_expired == true ? 'checked="checked"' : ''}>
                            True <input type="radio" name="account_expired" id="account_expired" value="${false}"
                            ${it.account_expired == false ? 'checked="checked"' : ''}>
                            False</td>
                    </tr>
                    <tr>
                        <td><label for="password"><g:message code="default.searchcustomer.password.message" />:</label></td>
                        <td><input type="password" name="password" id="password"
                            style="border: 1px solid black" value="${it.password}" /></td>
                    </tr>
                    <tr>
                        <td><label for="email"><g:message code="default.searchcustomer.email.message" />:</label></td>
                        <td><input type="text" name="email" id="email"
                            style="border: 1px solid black" value="${it.email}" /></td>
                    </tr>
                    </table>
                    </g:each> 
                            </form>
                  </div>

我确实在其中实现了一些ajax,但我不知道为什么验证不起作用,并阻止我提交表单。有人可以帮助我吗?非常感谢你们。

form 中定义操作

<form id="editUser" method="post" name="editUser" action="">

您似乎正在循环中输出"editpage"表。如果输出了多个元素,那么最终会得到许多具有相同名称和id的元素,这是无效的。当单击"更新"时,验证可能会查看包含id的第一个字段,而不是您试图验证的字段。

当然,所有这些都提供了${Query1}返回多个行。

如果在单击"更新"时删除了对话框,但没有提交表单,我想在关闭对话框之前尝试提交表单也是值得的,尽管我怀疑这会有什么不同,因为关闭对话框只会隐藏它。

最新更新