Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

maytham553's avatar

Filament 3: Enforce unique “name” across nested Builder/Repeater items and show per-field errors (not parent)

Question

  • Goal: Prevent duplicate field name values in a dynamic form builder, and show the validation error next to the offending TextInput, not at the end of the builder.
  • Structure: A SectionsBuilder (custom) contains a FormBuilder (custom). Each form field has a TextInput::make('name').

What I tried:

  • Added ->distinct() to the shared TextInput('name') used by all field components (Filament 3.2).
  • Tried parent-level ->rule() closures on SectionsBuilder / FormBuilder that scan the array and call $fail(...).

Problems:

  • ->distinct() doesn’t seem to enforce uniqueness across items spanning multiple sections (nested structure).
  • Parent ->rule() validates, but the error shows on the parent component (bottom of the builder), not on the specific name inputs.

How can I:

  1. Enforce uniqueness of name across all items, including across sections.
  2. Show validation errors next to each duplicate TextInput('name'), not only on the parent?

Environment:

  • Filament 3.2

Relevant code (from my project)

Minimal reproducible (simplified)

Builder::make('sections')->schema([
    // Each section has nested fields
    Repeater::make('fields')->schema([
        TextInput::make('name')->required()->distinct(), // want uniqueness across ALL sections
    ]),
]);

Desired behavior:

If two items anywhere (even across sections) have the same name, show the error directly under each offending TextInput, not on the parent.

Questions

  • Does ->distinct() support cross-nested validation scopes, or only direct siblings within a single repeater/builder?
  • If cross-section uniqueness needs a parent-level rule, how can I map failures to each duplicate child field so errors render on the corresponding TextInput('name')?
  • Is there a recommended Filament 3 way to assign validation errors to specific nested item paths (e.g., sections.0.fields.2.name) from a parent ->rule() closure?
0 likes
0 replies

Please or to participate in this conversation.