diff --git a/packages/forms/docs/12-repeater.md b/packages/forms/docs/12-repeater.md index f3e980de2d..7b3b510690 100644 --- a/packages/forms/docs/12-repeater.md +++ b/packages/forms/docs/12-repeater.md @@ -508,6 +508,20 @@ Repeater::make('members') +## Numbering repeater items + +You can add the repeater item's number next to its label using the `itemNumbers()` method: + +```php +use Filament\Forms\Components\Repeater; + +Repeater::make('members') + ->schema([ + // ... + ]) + ->itemNumbers() +``` + ## Simple repeaters with one field You can use the `simple()` method to create a repeater with a single field, using a minimal design diff --git a/packages/forms/src/Components/Repeater.php b/packages/forms/src/Components/Repeater.php index 26c182ec01..aa3adffbce 100644 --- a/packages/forms/src/Components/Repeater.php +++ b/packages/forms/src/Components/Repeater.php @@ -61,6 +61,8 @@ class Repeater extends Field implements CanConcealComponents, HasExtraItemAction protected string | Closure | null $itemLabel = null; + protected bool | Closure $hasItemNumbers = false; + protected Field | Closure | null $simpleField = null; protected Alignment | string | Closure | null $addActionAlignment = null; @@ -1036,6 +1038,13 @@ class Repeater extends Field implements CanConcealComponents, HasExtraItemAction return $this; } + public function itemNumbers(bool | Closure $condition = true): static + { + $this->hasItemNumbers = $condition; + + return $this; + } + public function fillFromRelationship(): void { $this->state( @@ -1173,6 +1182,11 @@ class Repeater extends Field implements CanConcealComponents, HasExtraItemAction return $this->itemLabel !== null; } + public function hasItemNumbers(): bool + { + return (bool) $this->evaluate($this->hasItemNumbers); + } + public function simple(Field | Closure | null $field): static { $this->simpleField = $field;