Skip to content

Instantly share code, notes, and snippets.

@Miri92
Last active May 1, 2018 03:36
Show Gist options
  • Save Miri92/75f6bfedf7ffc35f485894793f8427ce to your computer and use it in GitHub Desktop.
Save Miri92/75f6bfedf7ffc35f485894793f8427ce to your computer and use it in GitHub Desktop.
jQuery Validation example - Add rules to spesific class
<script type="text/javascript">
$( document ).ready(function() {
$( "#elan_form" ).validate({
//errorClass: '',
errorElement: "div",
errorPlacement: function ( error, element ) {
// Add the `help-block` class to the error element
error.addClass( "invalid-feedback" );
if ( element.prop( "type" ) === "checkbox" ) {
error.insertAfter( element.parent( "label" ) );
} else {
error.insertAfter( element );
}
},
highlight: function ( element, errorClass, validClass ) {
$( element ).parents( ".form-group" ).addClass( "has-error" ).removeClass( "has-success" );
},
unhighlight: function (element, errorClass, validClass) {
$( element ).parents( ".form-group" ).addClass( "has-success" ).removeClass( "has-error" );
}
});
$.validator.addMethod("required", $.validator.methods.required,
"Customer name required");
jQuery.validator.addClassRules("validation_element", {
required: true
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment