Redirect when cancelling instead of submitting a form

This commit is contained in:
Antoine Bartuccio 2024-12-20 20:21:36 +01:00
parent 044c6835d4
commit 244447c57a
3 changed files with 4 additions and 9 deletions

View File

@ -10,12 +10,11 @@ interface InitialFormData {
}
interface CounterConfig {
csrfToken: string;
clickApiUrl: string;
customerBalance: number;
customerId: number;
products: Record<string, Product>;
formInitial: InitialFormData[];
cancelUrl: string;
}
interface Product {
@ -132,11 +131,7 @@ exportToHtml("loadCounter", (config: CounterConfig) => {
},
cancel() {
this.basket = new Object({});
// We need to wait for the templated form to be removed before sending
this.$nextTick(() => {
this.finish();
});
location.href = config.cancelUrl;
},
handleCode() {

View File

@ -199,11 +199,10 @@
];
window.addEventListener("DOMContentLoaded", () => {
loadCounter({
csrfToken: "{{ csrf_token }}",
clickApiUrl: "{{ url('counter:click', counter_id=counter.id, user_id=customer.user.id) }}", customerBalance: {{ customer.amount }},
products: products,
customerId: {{ customer.pk }},
formInitial: formInitial,
cancelUrl: "{{ cancel_url }}",
});
});
</script>

View File

@ -260,6 +260,7 @@ class CounterClick(CounterTabsMixin, CanViewMixin, SingleObjectMixin, FormView):
product
)
kwargs["customer"] = self.customer
kwargs["cancel_url"] = self.get_success_url()
# To get all forms errors to the javascript, we create a list of error list
kwargs["form_errors"] = []