@@ -97,6 +97,11 @@ class Builder
97
97
*/
98
98
protected $ title ;
99
99
100
+ /**
101
+ * @var string
102
+ */
103
+ protected $ formClass ;
104
+
100
105
/**
101
106
* Builder constructor.
102
107
*
@@ -118,6 +123,8 @@ public function init()
118
123
{
119
124
$ this ->tools = new Tools ($ this );
120
125
$ this ->footer = new Footer ($ this );
126
+
127
+ $ this ->formClass = 'model-form- ' . uniqid ();
121
128
}
122
129
123
130
/**
@@ -487,10 +494,9 @@ public function open($options = []): string
487
494
488
495
$ attributes ['action ' ] = $ this ->getAction ();
489
496
$ attributes ['method ' ] = Arr::get ($ options , 'method ' , 'post ' );
497
+ $ attributes ['class ' ] = implode (' ' , ['form-horizontal ' , $ this ->formClass ]);
490
498
$ attributes ['accept-charset ' ] = 'UTF-8 ' ;
491
499
492
- $ attributes ['class ' ] = Arr::get ($ options , 'class ' );
493
-
494
500
if ($ this ->hasFile ()) {
495
501
$ attributes ['enctype ' ] = 'multipart/form-data ' ;
496
502
}
@@ -516,6 +522,38 @@ public function close(): string
516
522
return '</form> ' ;
517
523
}
518
524
525
+ /**
526
+ * @param string $message
527
+ */
528
+ public function confirm (string $ message )
529
+ {
530
+ $ trans = [
531
+ 'confirm ' => trans ('admin.confirm ' ),
532
+ 'cancel ' => trans ('admin.cancel ' ),
533
+ ];
534
+
535
+ $ script = <<<SCRIPT
536
+ $('form. {$ this ->formClass } button[type=submit]').click(function (e) {
537
+ e.preventDefault();
538
+ var form = $(this).parents('form');
539
+ swal({
540
+ title: " $ message",
541
+ type: "warning",
542
+ showCancelButton: true,
543
+ confirmButtonColor: "#DD6B55",
544
+ confirmButtonText: " {$ trans ['confirm ' ]}",
545
+ cancelButtonText: " {$ trans ['cancel ' ]}",
546
+ }).then(function (result) {
547
+ if (result.value) {
548
+ form.submit();
549
+ }
550
+ });
551
+ });
552
+ SCRIPT ;
553
+
554
+ Admin::script ($ script );
555
+ }
556
+
519
557
/**
520
558
* Remove reserved fields like `id` `created_at` `updated_at` in form fields.
521
559
*
0 commit comments