forked from SymfonyCasts/symfony-ux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path2ndcontroller-ajax-to-refresh-cart-list.diff
34 lines (33 loc) · 1.22 KB
/
2ndcontroller-ajax-to-refresh-cart-list.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
32
33
34
diff --git a/assets/controllers/cart-list_controller.js b/assets/controllers/cart-list_controller.js
index 6856d39..26abeaf 100644
--- a/assets/controllers/cart-list_controller.js
+++ b/assets/controllers/cart-list_controller.js
@@ -1,7 +1,12 @@
import { Controller } from 'stimulus';
export default class extends Controller {
- removeItem(event) {
- console.log(event.currentTarget);
+ static values = {
+ cartRefreshUrl: String,
+ }
+
+ async removeItem(event) {
+ const response = await fetch(this.cartRefreshUrlValue);
+ this.element.innerHTML = await response.text();
}
}
diff --git a/templates/cart/cart.html.twig b/templates/cart/cart.html.twig
index 4822828..f33e620 100644
--- a/templates/cart/cart.html.twig
+++ b/templates/cart/cart.html.twig
@@ -13,7 +13,9 @@
<h1>Shopping Cart</h1>
<div
class="component-light p-3"
- {{ stimulus_controller('cart-list') }}
+ {{ stimulus_controller('cart-list', {
+ cartRefreshUrl: path('_app_cart_list')
+ }) }}
>
{{ include('cart/_cartList.html.twig') }}
</div>