I'm stuggling with the removeClass from a jQuery function. I'm a newbie when it comes to jQuery and can't really think of an answer after a lot of search and testing.
I'm working with bootstrap. So, here's my HTML.
<form id="flogin" method="post" action="<?php echo site_url('entrar');?>" class="form-horizontal" role="form">
<fieldset>
<div class="input-group">
<span class="input-group-addon">@</span>
<input type="email" class="form-control" name="uemail" id="uemail" placeholder="Enter e-mail..">
</div>
<label for="uemail" class="error"></label>
<br />
<div class="input-group">
<span class="input-group-addon"><span class="glyphicon glyphicon-chevron-right"></span></span>
<input type="password" class="form-control" name="upasswd" id="upasswd" placeholder="Enter password...">
</div>
<label for="upasswd" class="error"></label>
<br />
<button type="submit" name="loginBtn" value="Ingresar" class="btn btn-default pull-right">Login</button>
<!--<input name="submit" type="submit" value="Submit">-->
</fieldset>
</form>
And this is is my jQuery code:
$("#flogin").validate({
onkeyup:true,
rules: {
uemail: "required",
upasswd: "required",
uemail: {
required: true,
email: true
},
upasswd: {
required: true,
minlength: 5
}
},
highlight: function(element) {
$(element).closest('.input-group').removeClass('has-success').addClass('has-error');
},
success: function(element) {
$(element).closest('.input-group').removeClass('has-error').addClass('has-success');
},
messages: {
uemail: "Por favor ingrese su email",
upasswd: "Por favor ingrese su contraseña",
uemail: {
required: "Por favor ingrese su email",
minlength: "Su e-mail debe ser valido.",
email: "Verifique que este bien escrito su e-mail"
},
password: {
required: "Por favor ingrese su contraseña",
minlength: "Tu contraseña debe contener al menos 5 carácteres."
}
}
});
I can't make this code work right, it validates but doesn't remove the has-error class after the e-mail has been entered correctly. Although it does add the has-error class when it's wrong but doesn't update when it's entered correctly again.
When I remove this peace of HTML it works, but I don't want the message there because it breaks the boxes and doesn't look good.
Any help would be pretty much appreciated.
Thank you.