Skip to content

Instantly share code, notes, and snippets.

@pounard
Created May 7, 2015 09:46
Show Gist options
  • Save pounard/42bb7f9270ebf596ac08 to your computer and use it in GitHub Desktop.
Save pounard/42bb7f9270ebf596ac08 to your computer and use it in GitHub Desktop.
Tiny JS code (jQuery, sorry guys) - that prevents double click on target forms.
// Prevent double click in some forms.
(function(jQuery) {
"use strict";
Drupal.behaviors.fixDoubleClick = {
attach: function (context) {
var k, selectors = [
"#comment-form"
// Add here forms with problems.
];
for (k in selectors) {
jQuery(context).find(selectors[k]).on("submit", function () {
jQuery(context).find("input[type=submit]").attr({
disabled: "disabled"
});
});
}
}
};
}(jQuery));
@pounard
Copy link
Author

pounard commented May 7, 2015

Oh, and that's for Drupal, if you want it generic, replace the Drupal.behavior.fooBar using a nice jQuery(document).ready({ /* ... */ }); instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment