jquery - Behaviour JqueryValidator and bootstrap 3, using Glyphicons -
i'm trying dig use of validators bootstrap 3 , glyphicons.
i developed small form showed below: name
</div> </div> <div class="form-group has-feedback"> <label for="inputpassword3" class="col-sm-2 control-label">surname</label> <div class="col-sm-10" id="surname"> <input type="text" class="form-control" placeholder="surname" name="surname"> </div> </div> <div class="form-group has-feedback"> <label for="inputpassword3" class="col-sm-2 control-label">telephone</label> <div class="col-sm-10"> <input type="tel" class="form-control" placeholder="telephone" name="telephone"> </div> </div> <div class="form-group has-feedback"> <label for="inputemail3" class="col-sm-2 control-label">email</label> <div class="col-sm-10"> <input type="email" class="form-control" id="inputemail3" placeholder="email" name="email"> </div> </div> <div class="form-group has-feedback"> <label for="inputpassword3" class="col-sm-2 control-label">password</label> <div class="col-sm-10"> <input type="password" class="form-control" id="inputpassword3" placeholder="password" name="password"> </div> </div> <div class="form-group has-feedback"> <div class="col-sm-offset-2 col-sm-10"> <div class="checkbox"> <label> <input type="checkbox"> remember me </label> </div> </div> </div> <div class="form-group"> <div class="col-sm-offset-2 col-sm-10"> <button type="submit" class="btn btn-default">sign in</button> </div> </div> </form>
the following jqueryscript:
<script> $(document).ready(function () { $('#frm_basic').validate({ rules: { surname: { minlength: 3, required: true, }, name: { minlength: 5, required: true, }, email: { minlength: 2, required: true, email: true }, password: { required: true, }, telephone : "validatephone" }, highlight: function(element) { var x=$(element).closest('.div').find("span"); $(element).closest('.form-group').removeclass('has-success').addclass('has-error'); $(element).closest('.form-group').find('[class^="glyphicon"]').remove(); $(element).closest('.form-group > div').append('<span class="glyphicon glyphicon-remove form-control-feedback"'+' aria-hidden="true"'+'id="statushigh">' ); }, unhighlight: function(element) { var y=$(element).closest('.div'); $(element).closest('.form-group').text(y.value); $(element).closest('.form-group').removeclass('has-error').addclass('has-success'); $(element).closest('.form-group').find('[class^="glyphicon"]').remove(); $(element).closest('.form-group > div').append('<span class="glyphicon glyphicon-ok form-control-feedback"'+' aria-hidden="true"' +'id="statusun">' ); }, success: function (element) { $(element).closest('.form-group').addclass('valid').closest('.control-group').removeclass('error').addclass('success'); } }); $.validator.addmethod("validatephone", function(value) { var filter = /^[0-9-+]+$/; if (filter.test(value)) { return true; } }, 'please enter right telephone number!'); }); </script>
now, want show results achieved:
i have style little bit different, let me explain better:
i glyphicons can appear in input field , not in second line below input. believe have found problem, when change class add new component/style:
besides, 'element' variable used applying function 'closest' starts real element? starting point?
thanks help,
try css:
form .glyphicon {margin-top: -20px;}
Comments
Post a Comment