Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using Async Parameters in Modal rendering #2710

Open
r4bick opened this issue Sep 8, 2023 · 4 comments
Open

Using Async Parameters in Modal rendering #2710

r4bick opened this issue Sep 8, 2023 · 4 comments
Assignees

Comments

@r4bick
Copy link

r4bick commented Sep 8, 2023

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.

@drabodan
Copy link
Contributor

drabodan commented Sep 8, 2023

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..

@r4bick
Copy link
Author

r4bick commented Sep 14, 2023

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 [
            
        ];
    }
}

@mrneatly
Copy link
Contributor

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.

@SimonErich
Copy link

Just had the same issue and the easiest solution is to just use request('my-parameter-key') inside of the Modal component class. Because the async request is a normal route call, this works perfectly fine. :)

hope this helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

5 participants