forked from SymfonyCasts/symfony-ux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery-also-ajax-on-direct-form-submit.diff
31 lines (30 loc) · 1.27 KB
/
jquery-also-ajax-on-direct-form-submit.diff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
diff --git a/assets/controllers/modal-form_controller.js b/assets/controllers/modal-form_controller.js
index ac2405a..8b51213 100644
--- a/assets/controllers/modal-form_controller.js
+++ b/assets/controllers/modal-form_controller.js
@@ -16,7 +16,8 @@ export default class extends Controller {
this.modalBodyTarget.innerHTML = await $.ajax(this.formUrlValue);
}
- async submitForm() {
+ async submitForm(event) {
+ event.preventDefault();
const $form = $(this.modalBodyTarget).find('form');
this.modalBodyTarget.innerHTML = await $.ajax({
url: this.formUrlValue,
diff --git a/templates/_modal.html.twig b/templates/_modal.html.twig
index 7568515..ae97d92 100644
--- a/templates/_modal.html.twig
+++ b/templates/_modal.html.twig
@@ -12,7 +12,11 @@
data-bs-dismiss="modal"
aria-label="Close"></button>
</div>
- <div class="modal-body" data-modal-form-target="modalBody">
+ <div
+ class="modal-body"
+ data-modal-form-target="modalBody"
+ data-action="submit->modal-form#submitForm"
+ >
{{ modalContent|default('Loading...') }}
</div>
<div class="modal-footer">