atk4 / ui

Robust and easy to use PHP Framework for Web Apps
https://atk4-ui.readthedocs.io
MIT License
440 stars 104 forks source link

Draggable CRUD not working inside modal action #2126

Open mkrecek234 opened 8 months ago

mkrecek234 commented 8 months ago

I have a crud which itself has an addModalAction that opens a modal show a child model's crud. If I addDraggable to that child model's crud, it throws an error:

$crud = \Atk4\Erp\Crud::addTo($app);
$crud->setModel($model = new Model\TicketType($app->db));

$crud->addModalAction(['icon'=>'tags'], ['title' => 'Edit tags'], function ($v, $id) use ($crud, $model) {
    $entity = (clone $model)->load($id);
    $crud2 = \Atk4\Ui\Crud::addTo($v);
    $crud2->setModel($entity->ref('TicketTags'));

    $dragHandler = $crud2->addDragHandler();
        $dragHandler->onReorder(function ($order) use ($model){

            $model->atomic(function () use ($model, $order) {
                foreach ($model as $entity) { $entity->save(['sort' => array_search($entity->id, $order)]); }
            });

           return new \Atk4\Ui\Js\JsToast('New sort order saved.');
        });

});

The error is API JavaScript Error Can't find variable: Draggable upon opening of the modal.

mvorisek commented 8 months ago

related with https://github.com/atk4/ui/issues/1875