Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Show delete buttons on the cart form

Adam Bogdałb36292dbfb2c
diff --git a/saleor/cart/static/js/delete_buttons.js b/saleor/cart/static/js/delete_buttons.js
new file mode 100644
index 0000000000..8fd3759df1
--- /dev/null
+++ b/saleor/cart/static/js/delete_buttons.js
@@ -0,0 +1,14 @@
+
+$.fn.addDeleteButtons = function() {
+ this.find('input[type="number"]').each(function(){
+ var icon = $('<i>').addClass('glyphicon glyphicon-trash');
+ var button = $('<button>').addClass('btn btn-danger delete-button').html(icon);
+ var container = $('<div>').addClass('input-group-btn').html(button);
+ $(this).after(container);
+ $(this).parent().addClass('input-group');
+ });
+
+ this.find('.delete-button').click(function(){
+ $(this).parents('tr').find('input[type="number"]').val('0');
+ })
+};
diff --git a/saleor/cart/templates/cart/index.html b/saleor/cart/templates/cart/index.html
index 24595d53d9..571ef7328c 100644
--- a/saleor/cart/templates/cart/index.html
+++ b/saleor/cart/templates/cart/index.html
@@ -2,6 +2,7 @@
{% load as_vertical_form from bootstrap %}
{% load gross from prices_i18n %}
{% load i18n %}
+{% load staticfiles %}
{% block title %}{% trans "Your cart" %} — {{ block.super }}{% endblock %}
@@ -15,7 +16,7 @@
<form role="form" action="." method="post">
{% csrf_token %}
{{ formset.management_form }}
- <table class="table table-striped">
+ <table class="table table-striped" id="cart-items">
<thead>
<tr>
<th class="col-sm-4">{% trans "Product" %}</th>
@@ -61,3 +62,11 @@
</p>
{% endif %}
{% endblock content %}
+
+{% block footer_scripts %}
+ {{ block.super }}
+ <script type="text/javascript" src="{% static "js/delete_buttons.js" %}"></script>
+ <script>
+ $('#cart-items').addDeleteButtons();
+ </script>
+{% endblock footer_scripts %}
\ No newline at end of file