diff --git a/docs/content/1_docs/4_form-fields/11_repeater.md b/docs/content/1_docs/4_form-fields/11_repeater.md index 838f0d829..1a64cf8d9 100644 --- a/docs/content/1_docs/4_form-fields/11_repeater.md +++ b/docs/content/1_docs/4_form-fields/11_repeater.md @@ -29,13 +29,15 @@ Repeater::make() :::#tab::: :::#tabs::: -| Option | Description | Type | Default value | -|:-------------|:---------------------------------------------|:--------|:-----------------| -| type | Type of repeater items | string | | -| name | Name of the field | string | same as `type` | -| max | Maximum amount that can be created | number | null (unlimited) | -| buttonAsLink | Displays the `Add` button as a centered link | boolean | false | -| reorder | Allow reordering of repeater items | boolean | true | +| Option | Description | Type | Default value | +|:---------------|:---------------------------------------------|:--------|:-----------------| +| type | Type of repeater items | string | | +| name | Name of the field | string | same as `type` | +| max | Maximum amount that can be created | number | null (unlimited) | +| buttonAsLink | Displays the `Add` button as a centered link | boolean | false | +| disableCreate | Disables ability to add new items | boolean | true | +| disableActions | Removes row item actions | boolean | true | +| disableReorder | Disables reordering of repeater items | boolean | true |
diff --git a/frontend/js/components/Repeater.vue b/frontend/js/components/Repeater.vue index 63355f90a..0f97a4f70 100755 --- a/frontend/js/components/Repeater.vue +++ b/frontend/js/components/Repeater.vue @@ -7,12 +7,13 @@ ref="blockList" :block="block" :index="index" - :withHandle="draggable" + :withHandle="reorder && draggable" + :withActions="displayActions" :size="blockSize" :opened="opened" > + v-if="hasRemainingBlocks && allowCreate">
@@ -110,11 +111,19 @@ type: Boolean, default: true }, + displayActions: { + type: Boolean, + default: true + }, max: { type: [Number, null], required: false, default: null - } + }, + reorder: { + type: Boolean, + default: true + }, }, data: function () { return { diff --git a/src/Services/Forms/Fields/Repeater.php b/src/Services/Forms/Fields/Repeater.php index 79c8c8373..36281184d 100644 --- a/src/Services/Forms/Fields/Repeater.php +++ b/src/Services/Forms/Fields/Repeater.php @@ -4,11 +4,13 @@ use A17\Twill\Services\Forms\Fields\Traits\CanReorder; use A17\Twill\Services\Forms\Fields\Traits\HasMax; +use A17\Twill\Services\Forms\Fields\Traits\DisableActions; class Repeater extends BaseFormField { use HasMax; use CanReorder; + use DisableActions; protected ?string $type = null; protected bool $buttonAsLink = false; diff --git a/src/Services/Forms/Fields/Traits/DisableActions.php b/src/Services/Forms/Fields/Traits/DisableActions.php new file mode 100644 index 000000000..98f7ee6e6 --- /dev/null +++ b/src/Services/Forms/Fields/Traits/DisableActions.php @@ -0,0 +1,18 @@ +displayActions = !$displayActions; + + return $this; + } +} diff --git a/src/Services/Forms/InlineRepeater.php b/src/Services/Forms/InlineRepeater.php index 13358df89..ba40578a7 100644 --- a/src/Services/Forms/InlineRepeater.php +++ b/src/Services/Forms/InlineRepeater.php @@ -9,6 +9,8 @@ use A17\Twill\Services\Forms\Fields\Repeater; use A17\Twill\Services\Forms\Traits\HasSubFields; use A17\Twill\Services\Forms\Traits\RenderForBlocks; +use A17\Twill\Services\Forms\Fields\Traits\CanReorder; +use A17\Twill\Services\Forms\Fields\Traits\DisableActions; use Illuminate\Contracts\View\View; use Illuminate\Support\Collection; use Illuminate\Support\Str; @@ -17,6 +19,8 @@ class InlineRepeater implements CanHaveSubfields, CanRenderForBlocks { use RenderForBlocks; use HasSubFields; + use CanReorder; + use DisableActions; protected function __construct( private ?string $name = null, @@ -207,6 +211,8 @@ public function render(): View ->name($this->name) ->type($this->getRenderName()) ->allowCreate($this->allowCreate) + ->disableReorder(!$this->reorder) + ->disableActions(!$this->displayActions) ->relation($this->relation ?? null) ->browserModule($this->allowBrowse ? $this->browser : null); diff --git a/src/View/Components/Fields/Repeater.php b/src/View/Components/Fields/Repeater.php index 431e44498..bdb47a0b4 100644 --- a/src/View/Components/Fields/Repeater.php +++ b/src/View/Components/Fields/Repeater.php @@ -11,6 +11,7 @@ public function __construct( public string $type, public bool $buttonAsLink = false, public bool $reorder = true, + public bool $displayActions = true, public ?int $max = null, public bool $allowCreate = true, public ?string $relation = null, diff --git a/views/partials/form/_repeater.blade.php b/views/partials/form/_repeater.blade.php index 6f62880e5..d3d6dae16 100644 --- a/views/partials/form/_repeater.blade.php +++ b/views/partials/form/_repeater.blade.php @@ -7,6 +7,7 @@ @if ($buttonAsLink) :button-as-link="true" @endif @if ($relation) relation="{{$relation}}" @endif :allow-create="{{$allowCreate ? 'true' : 'false'}}" + :display-actions="{{$displayActions ? 'true' : 'false'}}" > @unless($renderForBlocks)