Skip to content

Field with multiple dependencies #25

@alcohol

Description

@alcohol

I can't seem to get the following to work:

Form Foo with fields:

  • A / a checkbox type input
  • B / a choice type input
    • depends on A, if A is checked, B is not added
      ->addDependent('B', ['A'], function (DependentField $field, ?bool $checkbox): void {
        if ($checkbox) {
          return;
        }
        $field->add(ChoiceType::class, /* [...] */);
      }
  • C / a text type input
    • depends on A, if A is checked, C is not added, depends on B, options change based on the value of B
      ->addDependent('C', ['A', 'B'], function (DependentField $field, ?bool $checkbox, ?string $choice): void {
        if ($checkbox) {
          return;
        }
        $field->add(TextType::class, /* [...] */);
      }

The above doesn't work though; if I check A, B disappears, but C is still added (or not removed 🤷).

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