Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save miketaylr/232069 to your computer and use it in GitHub Desktop.
Save miketaylr/232069 to your computer and use it in GitHub Desktop.
//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