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
}
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
}