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

Wrapping a JSON field within a Panel causes the panel to be hidden #2

Closed
Naoray opened this issue Jan 11, 2021 · 4 comments
Closed
Labels
bug Something isn't working

Comments

@Naoray
Copy link
Owner

Naoray commented Jan 11, 2021

Text::make('Phone')
                ->rules('required', 'string'),

Panel::make('Brand Settings', [
                JSON::make('brand_settings', [
                    Image::make('Logo')->disk('public'),
                    Color::make('Primary Color')->swatches(),
                    Color::make('Secondary Color')->swatches(),
                ]),
            ]),

image

@Naoray Naoray added the bug Something isn't working label Jan 11, 2021
@elijahworkz
Copy link
Contributor

elijahworkz commented Jan 28, 2021

There are a couple of way to solve this without changing the code

  1. don't wrap JSON::make() in [] so it would look like this:
Panel::make('Brand Settings', 
                JSON::make('brand_settings', [
                    Image::make('Logo')->disk('public'),
                    Color::make('Primary Color')->swatches(),
                    Color::make('Secondary Color')->swatches(),
                ]),
            ),
  1. if you need other fields inside the Panel you can use splat operator like this:
Panel::make('Brand Settings', [
Text::make('Field'),
                ...JSON::make('brand_settings', [
                    Image::make('Logo')->disk('public'),
                    Color::make('Primary Color')->swatches(),
                    Color::make('Secondary Color')->swatches(),
                ]),
            ]),

added section to readme.md #4

@Naoray
Copy link
Owner Author

Naoray commented Feb 2, 2021

@elijahworkz I tested both approaches and none of them worked. First approach did throw errors related to the fact that the JSON class does not inherit from Field. Second approach is not possible because you can't deconstruct associative arrays with ...

@elijahworkz
Copy link
Contributor

@Naoray you're right. I forgot to add that you need to get the property 'data' from the top JSON field.

Like this:

  1. don't wrap JSON::make() in [] so it would look like this:
Panel::make('Brand Settings', 
                JSON::make('brand_settings', [
                    Image::make('Logo')->disk('public'),
                    Color::make('Primary Color')->swatches(),
                    Color::make('Secondary Color')->swatches(),
                ])->data,
            ),
  1. if you need other fields inside the Panel you can use splat operator like this:
Panel::make('Brand Settings', [
                Text::make('Field'),
                ...JSON::make('brand_settings', [
                    Image::make('Logo')->disk('public'),
                    Color::make('Primary Color')->swatches(),
                    Color::make('Secondary Color')->swatches(),
                ])->data,
            ]),

@Naoray
Copy link
Owner Author

Naoray commented Feb 2, 2021

@elijahworkz thanks. That works 🤝

@Naoray Naoray closed this as completed Feb 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants