Skip to content

Added feature for confirm cancel button text customizing #84

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

Open
wants to merge 1 commit into
base: master
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/.vscode
/vendor/
/node_modules
/node_modules
/.idea/*
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ You can require a confirmation for descructive actions
```php
Button::make('Cancel Account')->confirm('Are you sure?'),
Button::make('Cancel Account')->confirm('title', 'content'),
Button::make('Cancel Account')->confirm('title', 'content', 'Cancel'),
```

### Button state
Expand Down
2 changes: 1 addition & 1 deletion resources/js/components/DetailField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<a
style="order: 2;"
class="cursor-pointer btn text-80 font-normal px-3 mr-3 btn-link"
@click.prevent="openModal = false">Cancel</a>
@click.prevent="openModal = false" v-text="field.confirm.cancelButtonText"></a>
<nova-button v-bind="$props" @finished="modalReload" />
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion resources/js/components/IndexField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<a
style="order:2;"
@click.prevent="openModal = false"
class="cursor-pointer btn text-80 font-normal px-3 mr-3 btn-link" >Cancel</a>
class="cursor-pointer btn text-80 font-normal px-3 mr-3 btn-link" v-text="field.confirm.cancelButtonText"></a>
<nova-button
:field="field"
@finished="modalReload"
Expand Down
7 changes: 6 additions & 1 deletion src/Button.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,12 @@ public function classes($classes)
return $this;
}

public function confirm($message1 = null, $message2 = null)
public function confirm($message1 = null, $message2 = null, $cancelButtonText = null)
{
$this->confirm = [
'title' => __('Confirmation'),
'body' => null,
'cancelButtonText' => __('Cancel'),
];

if ($message1 && $message2 == null) {
Expand All @@ -150,6 +151,10 @@ public function confirm($message1 = null, $message2 = null)
$this->confirm['body'] = $message2;
}

if ($cancelButtonText) {
$this->confirm['cancelButtonText'] = $cancelButtonText;
}

return $this;
}

Expand Down