addModalAction - handling modal window


#1

Another one from my side :slight_smile:

I have a grid with rows and actions to be performed, I have created action for editing a row:

$g->addModalAction(['Edycja', 'Load', 'labeled', 'icon'=>'cogs'],'Edytuj slot', function ($j, $id) use ($g,$db) {
   $model_modal_new_slot = new Model_gcSlots_Group($db);
   $model_modal_new_slot->getRef('gc_slottype_id')->model = 'Model_gcSlotTypes_Group'; 
						
  $form3 = $j->add('Form',['segment']);
  $form3->setModel($model_modal_new_slot,['name','gc_slottype_id','gc_slot_order']);
  $form3->model->load($id);
  $form3->buttonSave->set('Zapisz');
  $form3->buttonSave->icon = 'save';
						
  $form3->onSubmit(function ($form3) use ($j,$g){
     $form3->model->Save;
     $j->js()->hide();
     return $g->jsReload();
  });
});

It changes the data, but I have no idea how to hide the modal window just on onSubmit event.

Anyone can help please ?


#2

This works for me:

return (new \atk4\ui\jQuery('.atk-modal'))->modal('hide');

If you want to return more than one JS action, return them as array:

return [
    (new \atk4\ui\jQuery('.atk-modal'))->modal('hide'),
    someotherjsaction,
    someotherjsaction,
];

Cheers
Philipp


#3

Thanks for feedback, unfortunetly this does not work for me. I have made a few experiments changing the jQuery reference to diffrent classes or idโ€™s and it works, but just for a first time. It looks that addModalAction create new div each time itโ€™s clicked and then jQuery is referencing only the first one.

Is there any way to reference modal created by the last use of addModalAction click ?


#4

For your grid, can you use the native canUpdate property of a CRUD to allow editing in a modal, to accomplish a similar function?