jQuery验证 - TypeError:t未定义

时间:2014-03-24 21:36:48

标签: javascript jquery validation jquery-validate requirejs

我正在处理一个使用jQuery Validation插件(http://jqueryvalidation.org/)的表单,但是,当触发验证时,我在jquery.validate.min.js中遇到了这个JS错误:

TypeError: t is undefined

所使用的每个元素的所有id等似乎排成一行,但不知何故,这仍然是一个问题。有任何想法吗?源代码在这里:

_new_user.html

<h2>New <span class='muted'>User</span></h2>

<script data-main="/assets/js/registration"
  src="/assets/js/require.js"></script>

<form id="form_register" class="form-horizontal" action="http://flyingsexsnak.es/users/create" accept-charset="utf-8" method="post">
<fieldset>

  <div id="step1_container" class="step_container">
    <h3>Register</h3>
    <div class="form-group">
      <label class="control-label" for="form_first_name">First Name</label>
      <input class="col-md-4 form-control" placeholder="First Name" required="required" maxlength="255" name="first_name" value="" type="text" id="form_first_name" />    
    </div>
    <div class="form-group">
      <label class="control-label" for="form_last_name">Last Name</label>
      <input class="col-md-4 form-control" placeholder="Last Name" required="required" maxlength="255" name="last_name" value="" type="text" id="form_last_name" />    
    </div>
    <div class="form-group">
      <label class="control-label" for="form_email">Email</label>
      <input class="col-md-4 form-control" placeholder="Email" required="required" maxlength="255" type="email" name="email" value="" id="form_email" />
    </div>
    <a id="step1_next">Next</a>
    <div id="step2_container" class="step_container">
    </div>
    <div id="step3_container" class="step_container">
    </div>
  </div>

</fieldset>
</form>

registration.js

require.config({
  baseUrl: '/assets/js',
  paths: {
    'jquery': 'jquery-1.11.0.min',
    'jquery-validation': 'jquery.validate.min',
    'user-edit': './lib/user-edit'
  },
  shim: {
    'jquery-validation': {
      deps: ['jquery']
    }
  }
});

require(['user-edit', 'jquery-validation'], function(UserEdit) {
  $(document).ready(function() {
    var userEdit = new UserEdit();
    userEdit.val = $("#form_register").validate();

    $('#step1_next').click(function() {
      userEdit.validateStep(1);
    });
    $('#step2_next').click(function() {
      userEdit.validateStep(2);
    });
    $('#step2_prev').click(function() {
      userEdit.validateStep(2);
    });
    $('#step3_prev').click(function() {
      userEdit.validateStep(3);
    });
  });
});

/lib/user-edit.js

define([], function() {
  var UserEdit = function(jquery) {
    if (typeof jquery !== 'undefined' ) {
      this.jquery = jquery;
    }
    else if (typeof global !== 'undefined') {
      this.jquery = global.$;
    }
    else {
      this.jquery = $;
    }
  };

  UserEdit.val = null;
  UserEdit.prototype.validateStep = function(step) {
    if (step === 1) {
      this.val.element(this.jquery('#form_first_name'));
      this.val.element(this.jquery('#form_last_name'));
      this.val.element(this.jquery('#form_email'));

      if (this.jquery('#form_first_name').valid()
        && this.jquery('#form_last_name').valid()
        && this.jquery('#form_email').valid()) {
        this.jquery('#step1_container').hide();
        this.jquery('#step2_container').show();
        this.jquery('#step3_container').hide();
      }
    }
    else if (step === 2) {}
    else if (step === 3) {}
  }
  return UserEdit;
});

0 个答案:

没有答案