web-dev-qa-db-fra.com

TypeError non capturé: impossible de lire la propriété «appel» de non défini

J'ai un formulaire préexistant que j'essaie d'ajouter la validation jquery à contenant:

<form id="form" method="POST" action="/title/">
    {% csrf_token %}
<input type="hidden" name="id" value="6">
<input type="hidden" name="custom_checkbox_Electronic_Signature_man" value="1">
                            <p> <span class="style9">First Name </span>
                              <input type="text" name="first_name" value="" size="20" class="style7"><span class="style9">
                            Last Name </span>
                              <input type="text" name="last_name" value="" size="20" class="style7"><span class="style9">

En utilisant le plugin de validation jquery, j'ai ajouté:

$('form').validate({
    rules: {
        first_name: {
            minlen: 3,
            maxlength: 15,
            required: true
        },
        last_name: {
            minlength: 3,
            maxlength: 15,
            required: true
        },
        email: {
          required: true,
          email: true
        },
         phone1: {
             required: true,
             phoneUS: true
          },
        phone2: {
             required: true,
             phoneUS: true
          },
            street: {
            required: true
          },
              city: {
            required: true
          },
              state: {
            required: true
          },
              Zip: {
            zipcodeUS: true
          }

    },
    highlight: function(element) {
        $(element).closest('.style9').addClass('.style13');
        //$(element).addClass('.style13');
    },
    unhighlight: function(element) {
        $(element).closest('.style9').removeClass('.style13');
        //$(element).removeClass('.style13');
    },
    errorElement: 'span',
    errorClass: 'style13',
    errorPlacement: function(error, element) {
        if(element.parent('.input-group').length) {
            error.insertAfter(element.parent());
        } else {
            error.insertAfter(element);
        }
    }
});

Je reçois l'erreur répertoriée ci-dessus. Qu'est-ce que je fais mal?

13
user61629

Remplacez minlen par minlength, et cela fonctionne, il n'y a pas de propriété minlen, donc call échoue en interne

$('form').validate({
    rules: {
        first_name: {
            minlength: 3,  // <- here
            maxlength: 15,
            required: true
        },
        last_name: {
            minlength: 3,
            maxlength: 15,
            required: true
        },
   ..........
17
adeneo

D'une manière générale, il s'agit d'une erreur qui peut être déclenchée si vous avez défini une règle de validation jQuery non valide.
Vous pouvez trouver les règles de validation valides en utilisant le lien this .

6
$(document).ready(function() {
    jQuery.validator.addMethod("noSpace", function(value, element){
            return value.indexOf("  ")<0 && value !==""; 
    }, "Space are not allowed");
});
2
Shakti Srivastav

essayer

jQuery(document).ready(function(){
                $('form').validate({
    rules: {
        first_name: {
            minlen: 3,
            maxlength: 15,
            required: true
        },
        last_name: {
            minlength: 3,
            maxlength: 15,
            required: true
        },
        email: {
          required: true,
          email: true
        },
         phone1: {
             required: true,
             phoneUS: true
          },
        phone2: {
             required: true,
             phoneUS: true
          },
            street: {
            required: true
          },
              city: {
            required: true
          },
              state: {
            required: true
          },
              Zip: {
            zipcodeUS: true
          }

    },
    highlight: function(element) {
        $(element).closest('.style9').addClass('.style13');
        //$(element).addClass('.style13');
    },
    unhighlight: function(element) {
        $(element).closest('.style9').removeClass('.style13');
        //$(element).removeClass('.style13');
    },
    errorElement: 'span',
    errorClass: 'style13',
    errorPlacement: function(error, element) {
        if(element.parent('.input-group').length) {
            error.insertAfter(element.parent());
        } else {
            error.insertAfter(element);
        }
    }
});
            });
0
websky