Created
November 11, 2009 16:01
-
-
Save miketaylr/232069 to your computer and use it in GitHub Desktop.
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
//The jQuery validate plugin validates on the name attribute, | |
//which is problematic in Rails because every checkbox | |
//gets a hidden input with the same name. | |
//Here's how to validate the checkbox, not the hidden input: | |
var validate = function(){ | |
$(':input:hidden').attr('name', 'new_name'); | |
$('form').validate({ | |
rules: {"checkbox": "required"}, | |
messages: {"checkbox": "CHECK ME"}, | |
submitHandler: function(form){ | |
//give the hidden checkbox its name back | |
//so nothing explodes on the backend | |
$(':input:hidden').attr('name', 'old_name'); | |
form.submit(); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment