mirror of
https://github.com/filamentphp/filament.git
synced 2026-09-24 15:42:09 +08:00
feat: add repeater item numbers
This commit is contained in:
@@ -508,6 +508,20 @@ Repeater::make('members')
|
||||
|
||||
<AutoScreenshot name="forms/fields/repeater/labelled" alt="Repeater with item labels" version="4.x" />
|
||||
|
||||
## Numbering repeater items
|
||||
|
||||
Unlike Builders, items in the repeater don't have a number next to their label by default. You may enable this using the `itemNumbers(true)` method:
|
||||
|
||||
```php
|
||||
use Filament\Forms\Components\Repeater;
|
||||
|
||||
Repeater::make('members')
|
||||
->schema([
|
||||
// ...
|
||||
])
|
||||
->itemNumbers(true)
|
||||
```
|
||||
|
||||
## Simple repeaters with one field
|
||||
|
||||
You can use the `simple()` method to create a repeater with a single field, using a minimal design
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
$reorderAction = $getAction($getReorderActionName());
|
||||
$extraItemActions = $getExtraItemActions();
|
||||
|
||||
$hasItemNumbers = $hasItemNumbers();
|
||||
$isAddable = $isAddable();
|
||||
$isCloneable = $isCloneable();
|
||||
$isCollapsible = $isCollapsible();
|
||||
@@ -154,6 +155,10 @@
|
||||
])
|
||||
>
|
||||
{{ $itemLabel }}
|
||||
|
||||
@if ($hasItemNumbers)
|
||||
{{ $loop->iteration }}
|
||||
@endif
|
||||
</{{ $itemLabelHeadingTag }}>
|
||||
@endif
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user