Skip to content

Commit

Permalink
On request, ability to confirm deletion, in Repeater.
Browse files Browse the repository at this point in the history
  • Loading branch information
tanthammar committed Mar 8, 2021
1 parent 4e77bab commit 7f4c936
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 1 deletion.
4 changes: 3 additions & 1 deletion resources/views/includes/array-wrapper.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
</button>
@endif

<button type="button" class="tf-repeater-delete-btn" wire:click.prevent="arrayRemove('{{ $field->name }}', '{{ $key }}')">
<button type="button" class="tf-repeater-delete-btn"
@if($field->confirm_delete) onclick="confirm('{{ trans($field->confirm_msg) }}') || event.stopImmediatePropagation();" @endif
wire:click.prevent="arrayRemove('{{ $field->name }}', '{{ $key }}')">
<x-tall-svg :path="config('tall-forms.trash-icon')" class="tf-repeater-btn-size" />
</button>
</div>
Expand Down
2 changes: 2 additions & 0 deletions resources/views/includes/file-loop.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
<div class="flex-1 px-2">{{ $file->getClientOriginalName() }}</div>
<button type="button" class="tf-file-upload-delete-btn"
onclick="confirm('{{ trans(config('tall-forms.are-u-sure')) }}') || event.stopImmediatePropagation();"
{{-- TODO remove previous line + uncomment next. See FileUpload class. --}}
{{-- @if($field->confirm_delete) onclick="confirm('{{ trans($field->confirm_msg) }}') || event.stopImmediatePropagation();" @endif --}}
wire:click.prevent="deleteSingleTempFile('{{ $field->name }}', '{{ isset($loop) ? $loop->index : null }}')">
<span class="px-2" wire:loading wire:target="deleteSingleTempFile"><x-tall-spinner /></span>
<x-tall-svg :path="config('tall-forms.trash-icon')" class="tf-file-upload-btn-size" />
Expand Down
17 changes: 17 additions & 0 deletions src/FileUpload.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ class FileUpload extends BaseField
public $maxBytes = null;
public $sizeLimitAlert;

//TODO Next major release, see confirmDelete() below
/*
public $confirm_delete = false;
public $confirm_msg = '';
*/

protected function overrides(): self
{
$this->type = 'file';
Expand Down Expand Up @@ -48,5 +54,16 @@ public function image(): self
return $this;
}

//TODO Decide default setting in next major release, see blade view resources/views/includes/file-loop.blade.php
/*
* Breaking change, until next release default behaviour is to confirm deletion.
* This MIGHT change to align with default setting in Repeater.
public function confirmDelete($message = ''): self
{
$this->confirm_delete = true;
$this->confirm_msg = filled($message) ? $message : config('tall-forms.are-u-sure');
return $this;
}
*/
}

9 changes: 9 additions & 0 deletions src/Repeater.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class Repeater extends BaseField

public $labelEachRow = false;
public $array_sortable = false;
public $confirm_delete = false;
public $confirm_msg = '';


protected function overrides(): self
Expand All @@ -36,4 +38,11 @@ public function labelEachRow(): self
$this->labelEachRow = true;
return $this;
}

public function confirmDelete($message = ''): self
{
$this->confirm_delete = true;
$this->confirm_msg = filled($message) ? $message : config('tall-forms.are-u-sure');
return $this;
}
}

0 comments on commit 7f4c936

Please sign in to comment.