A
A
Alexey2015-11-13 04:37:31
JavaScript
Alexey, 2015-11-13 04:37:31

How to specify an element during validation?

I use the jqueryvalidation.org plugin and
do it like this:

$("#add_form").validate({
    rules:{
      title:{
        required: true,
        minlength: 5,
        maxlength: 80
      }
    },
    messages:{
      title:{
          required: "Это поле обязательно для заполнения",
          minlength: "Минимум {0} символов",
          maxlength: "Максимум {0} символов",
      },
    },
  });

But when validating a form, I need to refer to the element inside the form not by the name attribute (as is done with the title), but by the class. In other words, how to use normal jquery selectors during form validation?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vladimir, 2015-11-13
@dzheka3d

If only so:

$( ".myinput" ).rules( "add", {
  required: true,
  minlength: 5 // ну и тд все ваши правила
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question