Last active
December 16, 2015 12:39
-
-
Save jrdmcgr/5435829 to your computer and use it in GitHub Desktop.
How to Extend Validity (http://validity.thatscaptaintoyou.com/)
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
// | |
// How to Extend Validity | |
// | |
// Setup validity and get the private validation function. | |
$.validity.setup({debugPrivates: true}) | |
var validate = $.validity.__private.validate | |
// Add our message | |
$.validity.messages.myCustomValidationMessage = 'You fail.' | |
// Write a custom validation method | |
$.fn.myCustomValidation = function (msg) { | |
return validate( | |
this, | |
function(obj) { | |
// do some custom stuff here. | |
}, | |
msg || $.validity.messages.myCustomValidationMessage | |
); | |
} | |
// Use this elsewhere in your code like any of the other validation methods. | |
$.validity.start() | |
$('.some-form-fields').myCustomValidation() | |
var results = $.validity.end() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment