Skip to content

Commit

Permalink
add option to disable sorting of inline repeaters
Browse files Browse the repository at this point in the history
  • Loading branch information
13twelve committed Jan 13, 2025
1 parent 90da826 commit 8b5bade
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 1 deletion.
6 changes: 5 additions & 1 deletion frontend/js/components/Repeater.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
ref="blockList"
:block="block"
:index="index"
:withHandle="draggable"
:withHandle="allowSortable && draggable"
:size="blockSize"
:opened="opened"
>
Expand Down Expand Up @@ -110,6 +110,10 @@
type: Boolean,
default: true
},
allowSortable: {
type: Boolean,
default: true
},
max: {
type: [Number, null],
required: false,
Expand Down
8 changes: 8 additions & 0 deletions src/Services/Forms/Fields/Repeater.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class Repeater extends BaseFormField
protected ?string $type = null;
protected bool $buttonAsLink = false;
protected bool $allowCreate = true;
protected bool $allowSortable = true;
protected ?string $relation = null;
protected ?array $browserModule = null;

Expand Down Expand Up @@ -63,6 +64,13 @@ public function allowCreate(bool $allowCreate = true): static
return $this;
}

public function allowSortable(bool $allowSortable = true): static
{
$this->allowSortable = $allowSortable;

return $this;
}

public function browserModule(?array $browserModule = null): static
{
$this->browserModule = $browserModule;
Expand Down
9 changes: 9 additions & 0 deletions src/Services/Forms/InlineRepeater.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ protected function __construct(
private ?Collection $fields = null,
private ?string $label = null,
private bool $allowCreate = true,
private bool $allowSortable = true,
private ?string $relation = null,
private ?bool $allowBrowse = false,
private ?array $browser = null,
Expand Down Expand Up @@ -95,6 +96,13 @@ public function disableCreate(bool $disableCreate = true): static
return $this;
}

public function disableSortable(bool $disableSortable = true): static
{
$this->allowSortable = ! $disableSortable;

return $this;
}

/**
* The name of the module to use for selecting existing records. Not for json repeaters.
*/
Expand Down Expand Up @@ -207,6 +215,7 @@ public function render(): View
->name($this->name)
->type($this->getRenderName())
->allowCreate($this->allowCreate)
->allowSortable($this->allowSortable)
->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 @@ -13,6 +13,7 @@ public function __construct(
public bool $reorder = true,
public ?int $max = null,
public bool $allowCreate = true,
public bool $allowSortable = true,
public ?string $relation = null,
public ?array $browserModule = null,
// Generic
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'}}"
:allow-sortable="{{$allowSortable ? 'true' : 'false'}}"
></a17-repeater>

@unless($renderForBlocks)
Expand Down

0 comments on commit 8b5bade

Please sign in to comment.