I'd like to get the following jQuery code to run on any forms on my site:
(function($) {
// Hide any N/A radio buttons
$('.form-radio[value=_none]').parent().hide();
// Uncheck a radio button on double-click
$('.form-radio').dblclick(function(){
$(this).prop('checked', false);
});
})(jQuery);
I've read that I can probably just add it to my template.php file, but I'd like to put it in a module. How would I do that?
UPDATE:
Thanks for the suggestions! So I went with option 3 because it seemed to make the most sense to me for my use-case. I still wasn't getting my jQuery to actually work though. I've updated it to this now:
(function($){
Drupal.behaviors.doubleClickNA = {
attach: function (context) {
// Hide the N/A radio button
$('.form-radio[value=_none]').parent().hide();
// Enable the double-click unchecker function
$('.form-radio').dblclick(function(){
$(this).prop('checked', false);
$(this).parent().parent().$('.form-radio[value=_none]').prop('checked', true);
});
}
};
})(jQuery);
That seems to get the N/A radio button to disappear, but the second function still doesn't work. The $('document').ready part was the key for the first function (duh, right?), but I believe I need to use a behavior to get the double click action to work after the page as finished rendering. What more am I missing here?