alexwenzel / nova-dependency-container

A Laravel Nova field container allowing to depend on other fields values
MIT License
46 stars 33 forks source link

Fields in Dependency Container can not show on Index page #11

Closed DuyenNguyen66 closed 1 year ago

DuyenNguyen66 commented 2 years ago

I used a select field - Parent name on DependencyContainer. The selected option can be shown on detail, but not on Index. Is that a bug?

          DependencyContainer::make([
                Select::make('Parent name', 'parent_id')
                    ->options(
                        \App\Models\Category::whereCode('column')
                            ->whereNull('parent_id')
                            ->pluck('name', 'id'))
                    ->displayUsingLabels()
                    ->showOnIndex()
            ])->dependsOn('code', 'column'),

Detail image

Index image

alexwenzel commented 2 years ago

hi @DuyenNguyen66

all fields inside a dependency container are NOT displayed on index. you need to work around this fact.

e.g.

...
DependencyContainer::make([
    Select::make('Parent name', 'parent_id')
        ->options(
            \App\Models\Category::whereCode('column')
                ->whereNull('parent_id')
                ->pluck('name', 'id'))
        ->displayUsingLabels()
])->dependsOn('code', 'column'),

Select::make('Parent name ONLY for index', 'parent_id')
        ->options(
            \App\Models\Category::whereCode('column')
                ->whereNull('parent_id')
                ->pluck('name', 'id'))
        -> onlyOnIndex(),
...
DuyenNguyen66 commented 1 year ago

Thank for your answer. I can handle like your answer, it's ok for now. But I have another question. Can we use rules method in a dependency container? I placed rules method like picture but it's not working.

Example: image