nova-simple-repeatable icon indicating copy to clipboard operation
nova-simple-repeatable copied to clipboard

dependsOn for siblings

Open Norgul opened this issue 1 year ago • 4 comments

Created functionality to enable dependsOn for siblings.

Disclaimer: I haven't tested the feature extensively in each and every scenario, so if anyone else would benefit from this feature, please try it out and let me know if it fails somewhere.

Copying usage instructions I wrote in the readme:


dependsOn() function is made available for fields within the SimpleRepeatable. To make the feature available, be sure to use DependsOnSiblings trait on the resource you want to have dependsOn() available for sibling fields.

Key on which the field depends on is constructed out of two parts: {parent attribute}.{child attribute}. This key will be made available to fetch within the function via $request->get('parent.child').

Example:

SimpleRepeatable::make('Adding', 'parent', [
    // Depending on 1 field
    Text::make('Child'),
    Text::make('Dependent Child')
      ->dependsOn('parent.child', function ($field, NovaRequest $request, FormData $formData) {
          $attribute = $request->get('parent.child');
      }),

    // Depending on multiple fields
    Text::make('Second Child'),
    Text::make('Third Child'),
    Text::make('Really Dependent Child')
      ->dependsOn(['parent.second_child', 'parent.third_child'], function ($field, NovaRequest $request, FormData $formData) {
          $attribute1 = $request->get('parent.second_child');
          $attribute2 = $request->get('parent.third_child');
      }),

])

Norgul avatar Jul 17 '24 10:07 Norgul

Can depends on work for sibling depennds on filed outside simple repeatable?

Select::make('Test'); SimpleRepeatable::make('Adding', 'parent', [ Text::make('Child')->dependsOn('test'......., ]);

laravelwebdev avatar Sep 12 '24 06:09 laravelwebdev

@laravelwebdev if I remember correctly while testing, that feature should be available out-of-the-box, but it begs the question of what happens with your repeatable fields. Because if you added 10 fields, and then change Select to something else, all 10 fields will be affected.

Norgul avatar Sep 12 '24 06:09 Norgul

Hi, thanks for your PR!

Do you know why this is not merged yet?

keroth- avatar Jun 23 '25 08:06 keroth-

Hi, thanks for your PR!

Do you know why this is not merged yet?

No idea :)

Norgul avatar Jun 23 '25 11:06 Norgul