并非所有输入字段都使用jQuery验证

时间:2016-03-01 17:00:18

标签: jquery jquery-validate

我正在使用jQuery验证,出于某种原因,我对输入描述和down的规则不起作用。

我得到的控制台中唯一的错误是我的验证文件,即jQuery'版本1.14.0。

Uncaught TypeError: e[d].call is not a function
ajax.aspnetcdn.com/ajax/jquery.validate/1.14.0/jquery.validate.min.js:4 Uncaught TypeError: e[d].call is not a function

但是,在我添加说明规则之前,我认为我有这个错误。我这样做是正确的还是jQuery只设置了你可以使用的规则名称?如果是这种情况,我是否必须制定新的规则才能做到这一点,我将如何做到这一点。

输入名称 - 公司工作,为什么下面的工作不起作用?

<form action="" autocomplete="on" method="POST" id="project-information-form">
        <input type="text" class="input-borderless" id="project-name" name="name" placeholder="Your Name">
        <input type="text" class="input-borderless" id="title-roll" name="title" placeholder="Title/Role">
        <input type="email" class="input-borderless" id="project-email" name="email" placeholder="Email Address">
        <input type="number" class="input-borderless" id="project-number" name="phone" placeholder="Phone Number">
        <input type="text" class="input-borderless" id="project-company" name="company" placeholder="Company/URL">
        <textarea rows="3" class="input-borderless" id="project-description" name="description" placeholder="Describe the project"></textarea>
        <input type="text" class="input-borderless" id="project-source" name="referral" placeholder="How did you hear about us?">
        <input type="text" class="input-borderless" id="project-socialMedia" name="social" placeholder="Which of our social media influenced you the most?">
        <input type="text" class="input-borderless" id="project-humanTest" placeholder="Human Test: What day comess after Thursday?">
        <input type="submit" id="submit-project" class="submit-project-button" value="Send Project Inquiry">
    </form>
 $(function() {

   var iSelected = 0;
    var ranges = [{
      lower: 500,
      upper: 1000
    }, {
      lower: 1100,
      upper: 2000
    }, {
      lower: 2100,
      upper: 5000
    }, {
      lower: 5100,
      upper: 10000
    }, {
      lower: 11000,
      upper: 20000
    }, {
      lower: 21000,
      upper: 50000
    }, ];
 var wslider = $("#sliderBar").width() / (ranges.length);
 for (var i = 0; i < ranges.length; i++) {
   var range = $('<div class="rangedot"><div class="intervalCircle"></div></div>');
   var left = (100 / (ranges.length) * i);
   rangeleft = "calc(" + left + "% - 2px)";
   range.css({
     left: rangeleft,
     width: wslider
   });
   range.on("click", function(idx) {
     return function() {
      iSelected = idx;
       var sliderleft = wslider * idx;
       $("#sliderInterval").animate({
         left: sliderleft
       });
       $("#budgetAmount").text("$" + ranges[idx].lower.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",") + " - " + "$" + ranges[idx].upper.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","));
     };
   }(i));
   $("#sliderBar").append(range);
   $("#sliderInterval").css("width", wslider + "px");
 }
    //$("#sliderInterval").show().text("BUDGET");
      $("#budgetAmount").show().text("$500 - $1,000");

//Send the project email
    $("#submit-project").on("click", function(event) {
        //event.preventDefault();

      var project_name = $("#project-name").val();
      var title_roll = $("#title-roll").val();
      var project_email = $("#project-email").val();
      var project_number = $("#project-number").val();
      var project_company = $("#project-company").val();
      var project_description = $("#project-description").val();
      // var range_selected      =  iSelected;
      var range_upper = ranges[iSelected].upper;
      var range_lower = ranges[iSelected].lower;
      var project_source = $("#project-source").val();
      var project_socialMedia = $("#project-socialMedia").val();
      var project_humanTest = $("#project-humanTest").val();
      all_focused = [];
      $('.project-option-boxes.box_focused').each(function() {
        all_focused.push($(this).text());
      });

      $("#project-information-form").validate({
            onfocusout: true,
            rules: {
              name: {
                required: true,
                minlength: 2
              },
              title: {
                required: true,
                minlength: 2
              },
              email: {
                required: true,
                email: true
              },
              phone: {
                required: true,
                digits: true,
                minlength: 10
              },
              company: {
                required: true,
                minlength: 2
              },
              description: {
                required: true,
                minlength: 10
              },
              referral: {
                required: true,
                minlength: 3
              },
              social: {
                required: true,
                minlength: 3
              }
            },
            messages: {
              name: {
                required: "Please enter your name",
                minlength: "Your name seems a bit short, doesn't it?"
              },
              title: {
                required: "Please enter your title",
                minlength: "Your title seems a bit short, doesn't it?"
              },
              email: {
                required: "Please enter your email address",
                email: "Please enter a valid email address"
              },
              phone: {
                required: "Please enter your phone number",
                digits: "Please enter a valid phone number",
                minlength: "Your number seems a bit short, doesn't it?"
              },
              company: {
                required: "Please enter your company or url",
                minlength: "Your company/url seems a bit short. Please enter at least 2 characters"
              },
              description: {
                required: "Please enter your Project Description",
                minlength: "Your description seems a bit short, doesn't it?"
              },
              referral: {
                required: "Please enter how you heard about us",
                minlength: "Your response seems a bit short, doesn't it?"
              },
              social: {
                required: "Please enter which social media platform you know we are on",
                minlength: "Your social media source seems a bit short, doesn't it?"
              }
            },
            //To allow the validate to work as typing
            //onkeyup : true, 
            submitHandler: function(form) {

0 个答案:

没有答案