platform icon indicating copy to clipboard operation
platform copied to clipboard

Using Async Parameters in Modal rendering

Open r4bick opened this issue 10 months ago • 5 comments

Is your feature request related to a problem? Please describe. There is no possibility to get parameters that getting by async request in during specify modal layouts.

Describe the solution you'd like To have a method to get access to these params for more flexibility. Now we can get only access to result of query method.

r4bick avatar Sep 08 '23 08:09 r4bick

Perhaps you're talking about this - https://orchid.software/en/docs/modals/#asynchronous-data-loading

In general everything is similar to the usual work with data in a Screen, only for the Screen the data is prepared in query, and for the modal in the method indicated in ->async and then this data can be accessed in modal layouts..

drabodan avatar Sep 08 '23 09:09 drabodan

How could i decide the following problem:

In UserEditLayout i need to get access to User model that i get in asyncGetUser method to render layout depends on its state?

class UserListScreen extends Screen
{
    public function query(): iterable
    {
        return [
            'users' => User::with('roles')
                ->paginate(),
        ];
    }
    
    public function layout(): iterable
    {
        return [
            UserFiltersLayout::class,
            UserListLayout::class,

            Layout::modal('asyncEditUserModal', UserEditLayout::class)
                ->async('asyncGetUser'),
        ];
    }

    public function asyncGetUser(User $user): iterable
    {
        return [
            'user' => $user,
        ];
    }
}
class UserEditLayout extends Rows
{
    public function fields(): array
    {
        // need to access to User model
        return [
            
        ];
    }
}

r4bick avatar Sep 14 '23 04:09 r4bick

I have the same question. The documentation shows how to pass a variable to a modal, but there is no clear example how to refer to the passed variable from within the modal layout.

mrneatly avatar Apr 21 '24 20:04 mrneatly