Skip to content
This repository was archived by the owner on Oct 20, 2025. It is now read-only.

Commit 72e66ed

Browse files
committed
Confirm with danger button
1 parent 164ffed commit 72e66ed

File tree

8 files changed

+73
-7
lines changed

8 files changed

+73
-7
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
@extends('layout')
2+
3+
@section('content')
4+
5+
FormConfirmDanger
6+
7+
<x-splade-form confirm-danger :action="route('form.simple.submit')">
8+
<input v-model="form.name" dusk="name" />
9+
<button type="submit">Submit</button>
10+
</x-splade-form>
11+
12+
@endsection

app/routes/web.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
Route::view('form/background', 'form.background')->name('form.background');
107107

108108
Route::view('form/confirm', 'form.confirm')->name('form.confirm');
109+
Route::view('form/confirmDanger', 'form.confirmDanger')->name('form.confirmDanger');
109110
Route::view('form/customConfirm', 'form.customConfirm')->name('form.customConfirm');
110111
Route::view('form/passwordConfirm', 'form.passwordConfirm')->name('form.passwordConfirm');
111112
Route::view('form/passwordConfirmOnce', 'form.passwordConfirmOnce')->name('form.passwordConfirmOnce');

app/tests/Browser/FormTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,25 @@ public function it_can_ask_to_confirm_the_submit()
106106
});
107107
}
108108

109+
/** @test */
110+
public function it_can_ask_to_confirm_the_submit_with_a_danger_button()
111+
{
112+
$this->browse(function (Browser $browser) {
113+
$browser->visit('/form/confirmDanger')
114+
->waitForText('FormConfirmDanger')
115+
->type('@name', 'Splade')
116+
->press('Submit')
117+
->waitForText('Are you sure you want to continue?')
118+
->press('@splade-confirm-cancel')
119+
->waitUntilMissingText('Are you sure you want to continue?')
120+
->assertInputValue('@name', 'Splade')
121+
->press('Submit')
122+
->waitForText('Are you sure you want to continue?')
123+
->press('@splade-confirm-confirm')
124+
->waitForText('FormSimple'); // redirect
125+
});
126+
}
127+
109128
/** @test */
110129
public function it_can_ask_to_confirm_the_submit_with_custom_texts()
111130
{

lib/Components/Confirm.vue

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,12 @@ export default {
9898
? Splade.confirmModal.value.confirmPasswordOnce
9999
: false;
100100
},
101+
102+
confirmDanger: function () {
103+
return Splade.confirmModal.value?.confirmDanger
104+
? Splade.confirmModal.value.confirmDanger
105+
: false;
106+
},
101107
},
102108
103109
watch: {
@@ -187,6 +193,7 @@ export default {
187193
confirmButton: this.confirmButton,
188194
cancelButton: this.cancelButton,
189195
confirmPassword: this.confirmPassword,
196+
confirmDanger: this.confirmDanger,
190197
191198
isOpen: this.isOpen,
192199
setIsOpen: this.setIsOpen,

lib/Components/Form.vue

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,20 @@ export default {
4848
},
4949
},
5050
51-
confirm: {
51+
confirmDanger: {
5252
type: [Boolean, String],
5353
required: false,
5454
default: false,
5555
},
5656
57+
confirm: {
58+
type: [Boolean, String],
59+
required: false,
60+
default: (props) => {
61+
return props.confirmDanger;
62+
},
63+
},
64+
5765
confirmText: {
5866
type: String,
5967
required: false,
@@ -410,7 +418,8 @@ export default {
410418
this.confirmButton,
411419
this.cancelButton,
412420
this.requirePassword ? true : false,
413-
this.requirePasswordOnce
421+
this.requirePasswordOnce,
422+
this.confirmDanger ? true : false
414423
)
415424
.then((password) => {
416425
if(!this.requirePassword) {

lib/Components/Link.vue

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,20 @@ const props = defineProps({
5252
default: false,
5353
},
5454
55-
confirm: {
55+
confirmDanger: {
5656
type: [Boolean, String],
5757
required: false,
5858
default: false,
5959
},
6060
61+
confirm: {
62+
type: [Boolean, String],
63+
required: false,
64+
default: (props) => {
65+
return props.confirmDanger;
66+
},
67+
},
68+
6169
confirmText: {
6270
type: String,
6371
required: false,
@@ -139,7 +147,8 @@ function navigate() {
139147
props.confirmButton,
140148
props.cancelButton,
141149
props.requirePassword ? true : false,
142-
props.requirePasswordOnce
150+
props.requirePasswordOnce,
151+
props.confirmDanger ? true : false
143152
)
144153
.then((filledPassword) => {
145154
if(!props.requirePassword) {

lib/Splade.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ const confirmModal = ref(null);
342342
* Shows the confirm modal with the given texts and
343343
* returns a promise to listen for the response.
344344
*/
345-
function confirm(title, text, confirmButton, cancelButton, confirmPassword, confirmPasswordOnce) {
345+
function confirm(title, text, confirmButton, cancelButton, confirmPassword, confirmPasswordOnce, confirmDanger) {
346346
let resolvePromise;
347347
let rejectPromise;
348348

@@ -354,6 +354,10 @@ function confirm(title, text, confirmButton, cancelButton, confirmPassword, conf
354354
confirmPasswordOnce = false;
355355
}
356356

357+
if (typeof confirmDanger === "undefined") {
358+
confirmDanger = false;
359+
}
360+
357361
const promise = new Promise((resolve, reject) => {
358362
resolvePromise = resolve;
359363
rejectPromise = reject;
@@ -367,7 +371,8 @@ function confirm(title, text, confirmButton, cancelButton, confirmPassword, conf
367371
resolvePromise,
368372
rejectPromise,
369373
confirmPassword,
370-
confirmPasswordOnce
374+
confirmPasswordOnce,
375+
confirmDanger
371376
};
372377

373378
return promise;

resources/views/components/confirm.blade.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@ class="rounded-md block w-full border-0 focus:border-indigo-300 focus:ring focus
4848
<button
4949
dusk="splade-confirm-confirm"
5050
type="button"
51-
class="inline-flex justify-center w-full rounded-md border border-transparent shadow-sm px-4 py-2 bg-blue-600 text-base font-medium text-white hover:bg-blue-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blue-500 sm:w-auto sm:text-sm"
51+
class="inline-flex justify-center w-full rounded-md border border-transparent shadow-sm px-4 py-2 text-base font-medium text-white focus:outline-none focus:ring-2 focus:ring-offset-2 sm:w-auto sm:text-sm"
52+
:class="{
53+
'bg-indigo-500 hover:bg-indigo-700 focus:ring-indigo-500': !confirm.confirmDanger,
54+
'bg-red-500 hover:bg-red-700 focus:ring-red-500': confirm.confirmDanger
55+
}"
5256
@click.prevent="confirm.confirm"
5357
:disabled="confirm.submitting"
5458
v-text="confirm.confirmButton"

0 commit comments

Comments
 (0)