Last active
January 4, 2016 22:19
-
-
Save kalpesh-fulpagare/8686833 to your computer and use it in GitHub Desktop.
Jquery Validation
This file contains 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
$("form.validate:not([novalidate])").each(function() { | |
formValidations = { | |
errorElement: "span", | |
errorClass: "errorField", | |
rules: {}, | |
messages: {} | |
}; | |
$(this).find("input, select, textarea").each(function() { | |
if ($(this).data("rules") !== undefined) { | |
formValidations['rules'][$(this).attr('name')] = $(this).data("rules"); | |
} | |
if ($(this).data("messages") !== undefined) { | |
formValidations['messages'][$(this).attr('name')] = $(this).data("messages"); | |
} | |
}); | |
$(this).validate(formValidations); | |
}); |
This file contains 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
<%= text_field_tag "city", '', class: "form-control", data: {rules: {required: true, minlength: 2, lettersonly: true}, messages: {required: "Please enter your city"}} %> | |
<%= text_field_tag "zip", '', class: "form-control", data: {rules: {required: true, minlength: 4, maxlength: 8, digits: true}, messages: {required: "Please enter zip number", digits: "Please enter number only", minlength: "Short zip number"}}, maxlength: 8 %> |
This file contains 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
#https://github.com/jzaefferer/jquery-validation | |
//= require jquery.validate.min | |
root = exports ? this | |
$(document).ready -> | |
s = undefined | |
UserAuthentication = | |
settings: | |
userLoginForm: $(".userLoginForm") | |
init: -> | |
s = @settings | |
@bindUIActions() | |
bindUIActions: -> | |
s.userLoginForm.validate | |
errorElement: "span" | |
errorClass: "errorSpan" | |
rules: | |
"user[email]": "required" | |
"user[password]": "required" | |
messages: | |
"user[email]": | |
required: "Please enter email" | |
"user[password]": | |
required: "Please enter password" | |
UserAuthentication.init() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment