Skip to content

Instantly share code, notes, and snippets.

@guoxiangke
Created May 4, 2014 09:22
Show Gist options
  • Save guoxiangke/0dffa7722a67f052c7ce to your computer and use it in GitHub Desktop.
Save guoxiangke/0dffa7722a67f052c7ce to your computer and use it in GitHub Desktop.
ajax node form submit ,check before submit
(function ($) {
Drupal.behaviors.confirm = {
attach: function(context, settings) {
var events = $('.node-weibo-form input[name=op]').data('events'); // Get the jQuery events.
$('.node-weibo-form input[name=op]').unbind('mousedown'); // Remove the click events.
var name = $('.node-weibo-form input[name=title]').val();
$('.node-weibo-form input[name=op]').mousedown(function () {
// var events = $('.node-weibo-form input[name=op]').clone(true).data('events');// Get the jQuery events.
// $('.node-weibo-form input[name=op]').unbind('mousedown'); // Remove the click events.
var name = $('.node-weibo-form input[name=title]').val();
if (name != '姓名') {
$.each(events.click, function() {
//Uncaught TypeError: Cannot read property 'click' of undefined??????
this.handler(); // Invoke the mousedown handlers that was removed.
});
}else{
alert('必须要填写姓名!');
$('.node-weibo-form input[name=title]').focus();
}
// Prevent default action.
return false;
});
}
}
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment