Y
Y
Yuri Avanesov2015-11-01 20:40:29
JavaScript
Yuri Avanesov, 2015-11-01 20:40:29

jquery validation setting?

Hello!
Please help me deal with the situation.

On my website, I implemented field validation in mail forms through a special jquery plugin jquery validation. The installation of the plugin turned out to be quite simple, there were no problems with it.

The essence of the plugin is that if the field does not pass the test, then after the field a special label with the .error class appears , to which I can set any styles via css. If the field passes validation, then the label is set to display:none and the input is set to the class . valid . Actually the question is as follows: how to assign the class .valid not to input, but


one more label ?

thanks in advance!

Answer the question

In order to leave comments, you need to log in

4 answer(s)
S
Sergey Goryachev, 2015-11-01
@webirus

Counter question:
Show the code if you want the error to be explained to you.

M
mletov, 2015-11-01
@mletov

Of course you can do it like this

var form = $( "#myform" );
form.validate();
$( "button" ).click(function() {
  $("input.valid").removeClass("valid");
  $("label.need-class").addClass("valid");
});

But it seems to me that it is better to figure out why it was necessary to change the default behavior of the plugin at all, there is something unnatural in this.

V
Vitaly Inchin ☢, 2015-11-02
@In4in

.valid + label{
    color: green;
}

Did you get the direction?

S
Serdji, 2015-11-02
@ssumatokhin

And you have configured the form correctly. I myself used this plugin on my project, and it adds this class without any bicycles. If the form fails validation, it will

<label id="lastname-error" class="error" for="lastname">Введите не мение 3-х символов</label>

If passed
<label id="lastname-error" class="error valid" for="lastname">Готово!</label>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question