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:
@@ -435,6 +435,20 @@ Any fields that you use from `$state` should be `live()` if you wish to see the
|
||||
|
||||
<AutoScreenshot name="forms/fields/repeater/labelled" alt="Repeater with item labels" version="3.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
|
||||
|
||||
@@ -79,6 +79,7 @@
|
||||
@foreach ($containers as $uuid => $item)
|
||||
@php
|
||||
$itemLabel = $getItemLabel($uuid);
|
||||
$hasItemNumbers = $hasItemNumbers();
|
||||
$visibleExtraItemActions = array_filter(
|
||||
$extraItemActions,
|
||||
fn (Action $action): bool => $action(['item' => $uuid])->isVisible(),
|
||||
@@ -154,6 +155,10 @@
|
||||
])
|
||||
>
|
||||
{{ $itemLabel }}
|
||||
|
||||
@if ($hasItemNumbers)
|
||||
{{ $loop->iteration }}
|
||||
@endif
|
||||
</h4>
|
||||
@endif
|
||||
|
||||
|
||||
@@ -54,6 +54,8 @@ class Repeater extends Field implements Contracts\CanConcealComponents, Contract
|
||||
|
||||
protected string | Closure | null $itemLabel = null;
|
||||
|
||||
protected bool | Closure $hasItemNumbers = false;
|
||||
|
||||
protected Field | Closure | null $simpleField = null;
|
||||
|
||||
protected Alignment | string | Closure | null $addActionAlignment = null;
|
||||
@@ -1014,6 +1016,13 @@ class Repeater extends Field implements Contracts\CanConcealComponents, Contract
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function itemNumbers(bool | Closure $condition = true): static
|
||||
{
|
||||
$this->hasItemNumbers = $condition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function fillFromRelationship(): void
|
||||
{
|
||||
$this->state(
|
||||
@@ -1140,6 +1149,11 @@ class Repeater extends Field implements Contracts\CanConcealComponents, Contract
|
||||
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