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

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

Open
TheSETJ opened this issue Oct 27, 2020 · 3 comments
Open

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

TheSETJ opened this issue Oct 27, 2020 · 3 comments

Comments

@TheSETJ
Copy link

TheSETJ commented Oct 27, 2020

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.

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'),
    ];
}
@alberto-bottarini
Copy link
Collaborator

I suggest you this: epartment/nova-dependency-container#135

@alberto-bottarini
Copy link
Collaborator

Please upvote my PR epartment/nova-dependency-container#146

@smskin
Copy link

smskin commented Jan 12, 2022

I fixed conflicts in the new PR. Please upvote. epartment/nova-dependency-container#202

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

No branches or pull requests

3 participants