Last active
May 1, 2018 03:36
-
-
Save Miri92/75f6bfedf7ffc35f485894793f8427ce to your computer and use it in GitHub Desktop.
jQuery Validation example - Add rules to spesific class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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