PHP code example of formfeed-uk / nova-dependable-panel

1. Go to this page and download the library: Download formfeed-uk/nova-dependable-panel library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

formfeed-uk / nova-dependable-panel example snippets


    use FormFeed\DependablePanel\DependablePanel;

    public function fields(NovaRequest $request)
    {
        return [
            Select::make('Select', 'select')->options([
                'option1' => 'Option 1',
                'option2' => 'Option 2',
            ]),
            DependablePanel::make('Panel Title', [
                Text::make('Field 1'),
                Text::make('Field 2'),
            ])
            ->dependsOn(["select"], function (DependablePanel $panel, NovaRequest $request, FormData $formData) {
                if ($formData['select'] == "option1") {
                    $panel->hide();
                }
            }),
        ];
    }

    use FormFeed\DependablePanel\DependablePanel;

    public function fields(NovaRequest $request)
    {
        return [
            DependablePanel::make('Panel Title', [
                Select::make('Select', 'select')->options([
                    'option1' => 'Option 1',
                    'option2' => 'Option 2',
                ]),
                Text::make('Hide Field 1')
                    ->dependsOn(["select"], function (Text $field, NovaRequest $request, FormData $formData) {
                        if ($formData['select'] == "option1") {
                            $field->hide();
                        }
                    }),
                Text::make('Hide Field 2')
                    ->dependsOn(["select"], function (Text $field, NovaRequest $request, FormData $formData) {
                        if ($formData['select'] == "option1") {
                            $field->hide();
                        }
                    }),
                Text::make('Show Field 3')
                    ->hide()
                    ->dependsOn(["select"], function (Text $field, NovaRequest $request, FormData $formData) {
                        if ($formData['select'] == "option1") {
                            $field->show();
                        }
                    }),
                Text::make('Show Field 4')
                    ->hide()
                    ->dependsOn(["select"], function (Text $field, NovaRequest $request, FormData $formData) {
                        if ($formData['select'] == "option1") {
                            $field->show();
                        }
                    }),
            ])
            ->singleRequest(true);
        ];
    }

    use FormFeed\DependablePanel\DependablePanel;

    public function fields(NovaRequest $request)
    {
        return [
            DependablePanel::make('Panel Title', [
                Select::make('Select', 'select')->options([
                    'option1' => 'Option 1',
                    'option2' => 'Option 2',
                ]),
                Text::make('Field 1'),
                Text::make('Field 2'),
                Text::make('Field 3')
                ->dependsOn(['select'], function (Text $field, NovaRequest $request, FormData $formData) {
                    if ($formData['select'] == "option1") {
                        $field->readOnly(false);
                    }
                })
            ])
            ->dependsOn(["select"], function (DependablePanel $panel, NovaRequest $request, FormData $formData) {
                $panel->applyToFields(function (Field $field, NovaRequest $request, FormData $formData) {
                    if ($formData['select'] == "option1") {
                        $field->readOnly();
                    }
                });
            }),
        ];
    }

    use FormFeed\DependablePanel\DependablePanel;

    public function fields(NovaRequest $request)
    {
        return [
            DependablePanel::make('Panel Title', [
                Select::make('Select', 'select')->options([
                    'option1' => 'Option 1',
                    'option2' => 'Option 2',
                ]),
                Text::make('Field 1'),
                Text::make('Field 2'),
                Text::make('Field 3')
            ])
            ->separatePanel(true)   
        ];
    }

    use FormFeed\DependablePanel\DependablePanel;

    public function fields(NovaRequest $request)
    {
        return [
            Select::make('Select', 'select')->options([
                'option1' => 'Option 1',
                'option2' => 'Option 2',
            ]),
            DependablePanel::make('Panel Title', [
                Text::make('Field 1'),
                Text::make('Field 2'),
            ])
            ->singleRequest(true)
            ->dependsOn(["select"], function (DependablePanel $panel, NovaRequest $request, FormData $formData) {
                if ($formData['select'] == "option1") {
                    $panel->fields([
                        Text::make('Field 3'),
                        Text::make('Field 4'),
                    ]);
                }
            }),
        ];
    }

    use FormFeed\DependablePanel\DependablePanel;

    public function fields(NovaRequest $request)
    {
        return [
            Select::make('Select', 'select')->options([
                'option1' => 'Option 1',
                'option2' => 'Option 2',
            ]),
            Boolean::make('Readonly'),
            DependablePanel::make('Panel Title', [
                Text::make('Field 1'),
                Text::make('Field 2'),
            ])
            ->singleRequest(true)
            ->dependsOn(["select", "readonly"], function (DependablePanel $panel, NovaRequest $request, FormData $formData) {
                if ($formData['select'] == "option1") {
                    $panel->fields([
                        Text::make('Field 3')
                            ->dependsOn(["readonly"], function (Text $field, NovaRequest $request, FormData $formData) {
                                if ($formData['readonly']) {
                                    $field->readonly();
                                }
                            }),
                        Text::make('Field 4')
                            ->dependsOn(["readonly"], function (Text $field, NovaRequest $request, FormData $formData) {
                                if ($formData['readonly']) {
                                    $field->readonly();
                                }
                            }),
                    ]);
                }
            }),
        ];
    }

    protected function resolveDefaultValue(NovaRequest $request)
    {
        return Field::resolveDefaultValue($request);
    }