4

I'm trying to set an entwine hook to the save button inside a GridField edit form so that right before saving, a JavaScript function is executed.

I've tried the code below without success

$('button[type="submit"]').entwine({
    onclick: myFunction
});

What is the JavaScript code to hook an entwine onclick event on the GridField save button?

3dgoo
  • 15,716
  • 6
  • 46
  • 58
Semicolon
  • 1,904
  • 14
  • 26

1 Answers1

6

This bit of JavaScript will be called on press of the GridField save button.

(function($) {
    $.entwine('ss', function($){
        $('#Form_ItemEditForm_action_doSave').entwine({
            onclick: function(e) {
                console.log('Hello there');
                this._super(e);
            }
        });
    });
})(jQuery);

In SilverStripe 3.5 the default ID for the GridField save button is Form_ItemEditForm_action_doSave. If using the BetterButtons module the save button ID is Form_ItemEditForm_action_save.

3dgoo
  • 15,716
  • 6
  • 46
  • 58