0

I'm trying to customizing Jquery validation. I happened to change the style of the error message. How to change style of input? I need to change border color, if success - green border, if error - red border. And if success - add <span class="glyphicon glyphicon-ok" style="color:green;"> inside input. If if success - green border - already work. HTML:

<form role="form" action="" id="contact-form" >      
          <div class="form-group"> 
            <div class="controls" >       
            <input type="text"  class="form-control" name="login"  placeholder="LOGIN*"
            maxlength="15">         
            </div>
          </div>    
    </form>

CSS:

<style>  
    .valid {
    border-color: green;

    }
        label.error {
        font-family:Tahoma;
            font-size:11px;
            color: red;
            padding-left: 8px;          
        }       
  </style>

JS:

$(document).ready(function(){

        $('#contact-form').validate({
        rules: {
          login: {
            minlength: 2,
            required: true
          }       
        },
            highlight: function(element) {
                $(element).closest('.form-group').removeClass('success').addClass('error');
            },
            success: function(element) {
                element
                .text('OK!').addClass('valid')
                .closest('.form-group').removeClass('error').addClass('success');
            }
      });


}); 

2 Answers 2

1

your css mention that class under label type, yet there are no labels in your html code. try removing label from css

Sign up to request clarification or add additional context in comments.

2 Comments

Yes, it helped, but only for sucess state. For error i probably need 2 styles, one for label, and one for input.
1- make sure your "highlight" function is being called by adding an alert("something") or console.log("something"); 2- instead of using add / remove class, try the following: $(".form-control").css("bolder-color","red");
0

Try selecting the element by class, in this case ".form-input" and adding the class to this specifically. For border you are going to want to add the "border-style" or "border" property.

2 Comments

"Try selecting the element by class" - how to do it?
try adding the styling to the form input inside the div, instead of the form-group.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.