Address parent in onsubmit?

How can we address in an onsubmit action the parent function?
I’m setting up a grid and by clicking on a button a modal window opens using the model of the grid. When saving in the modal window I’d like to reload the grid.

class BecontactOverview extends \atk4\ui\Grid {

  public function init(): void {
    parent::init();

    $addButton = $this->menu->addItem([t('Add_client'), 'icon' => 'add square']);

    $modal = $this->app->add(['Modal', 'title' => t('New entry')]);
    $newentryForm = \atk4\ui\Form::addTo($modal);
    $newentryForm->setModel(new OverviewModel());

    $newentryForm->onSubmit(function($form) {
        return new \atk4\ui\JsReload(**???**);  // address the parent grid
    });

    $addButton->on('click', $modal->show());
}

This class gets called with
$o = BecontactOverview::addTo($v);

I added question marks ("???") where I need to know what to put in there…

Or do you have any other approach to achieve what I want?

Hello,

you can try $grid = $this; before defininf the onSubmit callback & then pass the grid in the scope with $newentryForm->onSubmit(function($form) use ($grid) {

From there you can do return new \atk4\ui\JsReload($grid->container);

Thanks!
$this is always pointing to the parent class

Therefore my solution for now that worked is as follows:

 $newentryForm->onSubmit(function($form) {
  $form->model->save();

  return [
    $this->modal->hide(),
    new \atk4\ui\JsToast('Entry successful'),
    new \atk4\ui\JsReload($this)
  ];
});
1 Like

Cool, glad this one worked out