Skip to content

dependsOn not working as expected for fields with the same attribute name #4936

@ThaDaVos

Description

@ThaDaVos
  • Laravel Version: 9.35.1
  • Nova Version: 4.16.1
  • PHP Version: 8.0.23
  • Database Driver & Version: MySQL 8.x
  • Operating System and Version: Ubuntu
  • Browser type and version: Firefox
  • Reproduction Repository: https://github.com/###/###

Description:

As discussed in #4648 there is an issue when using dependsOn with fields using the same attribute - in our case we're using two selects depending on a type field - based on the type a different select with different label is used - but due this issue, the first field is displayed twice in it's full.

Detailed steps to reproduce the issue on a fresh Nova installation:

See: #4648

Select::make('Field Type')
    ->options([
        'text' => 'Text',
        'number' => 'Number',
    ])
    ->onlyOnForms()
    ->displayUsingLabels(),

Number::make('Number', 'field_value')
    ->help('Number test')
    ->onlyOnForms()
    ->dependsOn(
        ['field_type'],
        function (Number $field, NovaRequest $request, FormData $formData) {
            if ($formData->field_type == 'number') {
                $field
                    ->show()
                    ->rules('required');
            } else {
                $field
                    ->hide();
            }
        }
    ),

Text::make('Text', 'field_value')
    ->help('Text test')
    ->onlyOnForms()
    ->dependsOn(
        ['field_type'],
        function (Text $field, NovaRequest $request, FormData $formData) {
            if ($formData->field_type == 'text') {
                $field
                    ->show()
                    ->rules('required');
            } else {
                $field
                    ->hide();
            }
        }
    ),

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions