Skip to content

Conversation

Norgul
Copy link

@Norgul Norgul commented Jul 17, 2024

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 Norgul mentioned this pull request Jul 17, 2024
@laravelwebdev
Copy link

laravelwebdev commented Sep 12, 2024

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

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

@Norgul
Copy link
Author

Norgul commented Sep 12, 2024

@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.

@keroth-
Copy link

keroth- commented Jun 23, 2025

Hi, thanks for your PR!

Do you know why this is not merged yet?

@Norgul
Copy link
Author

Norgul commented Jun 23, 2025

Hi, thanks for your PR!

Do you know why this is not merged yet?

No idea :)

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

Successfully merging this pull request may close these issues.

3 participants