Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix 2641: Inline repeater updates #2714

Open
wants to merge 6 commits into
base: 3.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions docs/content/1_docs/4_form-fields/11_repeater.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |

<br/>

Expand Down
15 changes: 12 additions & 3 deletions frontend/js/components/Repeater.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@
ref="blockList"
:block="block"
:index="index"
:withHandle="draggable"
:withHandle="reorder && draggable"
:withActions="displayActions"
:size="blockSize"
:opened="opened"
>
<a17-button slot="block-actions" variant="icon" data-action @click="duplicateBlock(index)"
v-if="hasRemainingBlocks">
v-if="hasRemainingBlocks && allowCreate">
<span v-svg symbol="add"></span>
</a17-button>
<div slot="dropdown-action">
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 2 additions & 0 deletions src/Services/Forms/Fields/Repeater.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
18 changes: 18 additions & 0 deletions src/Services/Forms/Fields/Traits/DisableActions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace A17\Twill\Services\Forms\Fields\Traits;

trait DisableActions
{
protected bool $actions = true;

/**
* Adds a border around the options.
*/
public function disableActions(bool $actions = true): static
{
$this->displayActions = !$actions;

return $this;
}
}
7 changes: 7 additions & 0 deletions src/Services/Forms/InlineRepeater.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -17,6 +19,8 @@ class InlineRepeater implements CanHaveSubfields, CanRenderForBlocks
{
use RenderForBlocks;
use HasSubFields;
use CanReorder;
use DisableActions;

protected function __construct(
private ?string $name = null,
Expand All @@ -32,6 +36,7 @@ protected function __construct(
private ?string $titleField = null,
private ?bool $hideTitlePrefix = false,
private ?bool $buttonAsLink = false,
private ?bool $displayActions = true,
protected ?array $connectedTo = null,
) {
}
Expand Down Expand Up @@ -207,6 +212,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);

Expand Down
1 change: 1 addition & 0 deletions src/View/Components/Fields/Repeater.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions views/partials/form/_repeater.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'}}"
></a17-repeater>

@unless($renderForBlocks)
Expand Down
Loading