dcasia / conditional-container

Provides an easy way to conditionally show and hide fields in your Nova resources.
MIT License
115 stars 37 forks source link

Conditional field is not being displayed inside a nested form #46

Closed TheSETJ closed 2 years ago

TheSETJ commented 3 years ago

Hey

I have a Post model which can be of 2 types: regular and poll. A Post model of type poll will be related to a Poll model in a 1-1 manner. Among all other attributes, a Poll model has selection_mode and max_selected_count. With all of these said, here is my issue:

I'm using yassipad/laravel-nova-nested-form to display create/update form of a Poll model inside create/update form its related Post. Also, I wrap max_selection_count field of Poll inside a ConditionalContainer field to make it visible only if selection_mode is equal to multiple.

Everything works fine in isolation, but when it comes to max_selection_count field inside the Post create/update page, it does not work as expected. Inside Post form and when type is poll, no matter what option I choose for selection_mode, max_selection_count will not appear (but it works inside Poll form isolated from Post form).

Here is my code snippets:

// app/Nova/Post.php
public function fields(Request $request)
{
    return [
        // ...
        Select::make('type')->options(['Regular' => 'regular', 'Poll' => 'poll']),
        ConditionalContainer::make([
            NestedForm::make('poll', Poll::class)
        ])->if('type = poll')
    ];
}
// app/Nova/Poll.php
public function fields(Request $request)
{
    return [
        // ...
        Select::make('selection_mode')->options(['Single' => 'single', 'Multiple' => 'multiple']),
        ConditionalContainer::make([
            Number::make('max_selection_count')
        ])->if('selection_mode = multiple'),
    ];
}