Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

SOLVED 3.1 GridField_FormAction confirmation before delete


4 Posts   303 Views


2 March 2014 at 12:55am Community Member, 46 Posts


Have a new form action button which does a calculated delete, and I need an "are you sure" before running.
Is there an agreed way to do this ?



2 March 2014 at 12:55pm Community Member, 46 Posts

SOLVED - I added a MyModelAdmin init function which required some JS in which I copied an action function from gridfield,js and added the test there.

.... easy when you know how !!!!!


2 March 2014 at 1:14pm Forum Moderator, 149 Posts

Would be useful if you can show the actual code here too for others attempting the same :)

Also if you can can add [solved] to the initial forum post it help people find it while searching... just some friendly pointers to help fellow developers.


2 March 2014 at 9:51pm (Last edited: 3 March 2014 10:19am), Community Member, 46 Posts

Ok sorry - thought a description would suffice....

Steps to implement this:-

a) get config and add component using an extension


class MyModelAdminExtension extends Extension {

   function updateEditForm(&$form)
      $f = $form->Fields()->fieldByName('ComingSoonItem'); // this is the DataObject name managed in MyAdmin.php
      // as MyAdmin manages more than one oage I need to be sure am on right page
      // so add try to add component if field exists
      if ($f) $f->getConfig()->addComponent(new GridFieldBigDelButton('before'));


b) then turn extension on in config.yaml

- MyModelAdminExtension

c) Write the new component added in a) - I started off with a copy of GridFieldExportgButton.php and amended the action handler
(Sorry can't give you the actual delete routine as it's sensitive ... but it does nothing clever - just deletes some rows in the gridfield

public function getHTMLFragments($gridField) {
      $button = new GridField_FormAction(
         $gridField, //grid on the form
         'DelHist', //name
         'Delete Historic', //title
         'delhistaction', //action name
      $button->setAttribute('data-icon', 'delhistoric');
// add my special class here
      return array(
         $this->targetFragment => '<p class="grid-delH-button">' . $button->Field() . '</p>',

   public function getActions($gridField) {
      return array('delhistaction');

   public function handleAction(GridField $gridField, $actionName, $arguments, $data) {
      if($actionName == 'delhistaction') {
         return $this->handleBigDelete($gridField);

d) Add an init function for js require to myadmin.php


class MyAdmin extends ModelAdmin {
private static $managed_models = array('ComingSoonItem','ServiceTypeItem');
private static $url_segment = 'comingsoon';
private static $menu_title = 'Manage coming Svcs';

public function init()


e) write the js file for d) - this is a copy of the no-ajax one from gridfield.js

// to add a confirm to delete button
      $.entwine('ss', function($) {
onclick: function(e){
            if(!confirm('Are you sure you want to delete ALL old records')) {
               return false;
            } else {
         }      });



f) That should be enough to get you started ....