Skip to content

Instantly share code, notes, and snippets.

@ThomasHambach
Created May 14, 2014 08:15
Show Gist options
  • Save ThomasHambach/467f3b6376f097bde024 to your computer and use it in GitHub Desktop.
Save ThomasHambach/467f3b6376f097bde024 to your computer and use it in GitHub Desktop.
Drupal 7 Execute custom function when doing AJAX load
(function($) {
Drupal.behaviors.contact = {
attach: function (context, settings) {
$('.webform-client-form input').attr('readonly', false);
// Actions are stored in Drupal.ajax, every ajax call these identifiers might change.
$.each(Drupal.ajax, function(k, v) {
if(k.match(/edit-submitted-about/g)) { // The identifier I was aiming for was prefixed with "edit-submitted-about".
Drupal.ajax[k].options.beforeSerialize = function(element, options) {
Drupal.ajax.prototype.beforeSerialize(element, options);
$('.webform-client-form input').attr('readonly', true);
}
}
});
};
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment