alexwenzel / nova-dependency-container

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

Nested Dependencies #35

Open DMeganoski opened 1 year ago

DMeganoski commented 1 year ago

I am trying to build a somewhat complex form, which has several dependency containers.

Let's use the examples 'provider' and 'service'. Let's say that each provider has it's own list of services. This is easy to achieve with this package.

The problem is if I want to add a third field that depends on the value of the service selected.

If I use ->dependsOn('service', 'value') this does not seem to pick up the value and does not show the container when it should.

Is there some prefix I need to add to 'service' since it's inside a dependency container?

Any suggestions are much appreciated.

boris-shakhverdyan commented 8 months ago

Do you solve it?

DMeganoski commented 8 months ago

@boris-shakhverdyan I instead leveraged the default 'dependsOn' function.

Instead of hiding the field in some cases, the field is always there, but inside the 'dependsOn' callback I am using $field->options($newOptions) to set the available items when another field changes. image

boris-shakhverdyan commented 8 months ago

@boris-shakhverdyan I instead leveraged the default 'dependsOn' function.

Instead of hiding the field in some cases, the field is always there, but inside the 'dependsOn' callback I am using $field->options($newOptions) to set the available items when another field changes. image

DependencyContainer::make([ Text::make("test")->dependsOn(["info"], function($field, $request, $formdata) { //This function not run } ])->dependsOnNotEmpty("key2")