Skip to content

Instantly share code, notes, and snippets.

@sumanthkumarc
Last active August 11, 2016 10:53
Show Gist options
  • Save sumanthkumarc/a61088cccf86722065dfa4b68711f386 to your computer and use it in GitHub Desktop.
Save sumanthkumarc/a61088cccf86722065dfa4b68711f386 to your computer and use it in GitHub Desktop.
Drupal - Control ajax call on submit button by returning true or false in beforesubmit function
// Get all the elements in the DOM with ajax enabled
for (var ajax_element in Drupal.ajax) {
if (typeof Drupal.ajax[ajax_element] !== 'undefined') {
// Drupal.ajax[ajax_elements].ajaxing = false;
// Get the actual jquery object for the submit button
var $ajax_el_obj = jQuery(Drupal.ajax[ajax_element].element);
// Check if it's reqd. button and then call beforesubmit for that
if($ajax_el_obj.attr('id') == 'edit-submit'){
console.log('second step button');
Drupal.ajax[ajax_element].options.beforeSubmit = function (form_values, element, options)
{
// Check reqd. validations or conditions and return true/false
return false;
};
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment