Only return HTTP 422 while validating the invoice’s form if not HTMx

This commit is contained in:
jordi fita mas 2023-04-19 19:18:29 +02:00
parent 754da87e45
commit 835bab357e
1 changed files with 6 additions and 2 deletions

View File

@ -463,7 +463,9 @@ func HandleAddInvoice(w http.ResponseWriter, r *http.Request, _ httprouter.Param
return return
} }
if !form.Validate() { if !form.Validate() {
w.WriteHeader(http.StatusUnprocessableEntity) if !IsHTMxRequest(r) {
w.WriteHeader(http.StatusUnprocessableEntity)
}
mustRenderNewInvoiceForm(w, r, form) mustRenderNewInvoiceForm(w, r, form)
return return
} }
@ -840,7 +842,9 @@ func HandleUpdateInvoice(w http.ResponseWriter, r *http.Request, params httprout
} else { } else {
slug := params[0].Value slug := params[0].Value
if !form.Validate() { if !form.Validate() {
w.WriteHeader(http.StatusUnprocessableEntity) if !IsHTMxRequest(r) {
w.WriteHeader(http.StatusUnprocessableEntity)
}
mustRenderEditInvoiceForm(w, r, slug, form) mustRenderEditInvoiceForm(w, r, slug, form)
return return
} }