From 835bab357e53ba8431f55ec4b0875b21559c65f4 Mon Sep 17 00:00:00 2001 From: jordi fita mas Date: Wed, 19 Apr 2023 19:18:29 +0200 Subject: [PATCH] =?UTF-8?q?Only=20return=20HTTP=20422=20while=20validating?= =?UTF-8?q?=20the=20invoice=E2=80=99s=20form=20if=20not=20HTMx?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/invoices.go | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/pkg/invoices.go b/pkg/invoices.go index 6225607..da3c52d 100644 --- a/pkg/invoices.go +++ b/pkg/invoices.go @@ -463,7 +463,9 @@ func HandleAddInvoice(w http.ResponseWriter, r *http.Request, _ httprouter.Param return } if !form.Validate() { - w.WriteHeader(http.StatusUnprocessableEntity) + if !IsHTMxRequest(r) { + w.WriteHeader(http.StatusUnprocessableEntity) + } mustRenderNewInvoiceForm(w, r, form) return } @@ -840,7 +842,9 @@ func HandleUpdateInvoice(w http.ResponseWriter, r *http.Request, params httprout } else { slug := params[0].Value if !form.Validate() { - w.WriteHeader(http.StatusUnprocessableEntity) + if !IsHTMxRequest(r) { + w.WriteHeader(http.StatusUnprocessableEntity) + } mustRenderEditInvoiceForm(w, r, slug, form) return }