Add the formnovalidate attribute to update and add products buttons

They are to complete the invoice, so it can be in an invalid date, but
we do not want to force people to finish all required inputs before they
can add products or update quantities, do we?

Now had to add the empty option label for customer in all cases, because
it could be empty, although that should be done regardless in case
someone has a browser that does not validate fields.
This commit is contained in:
jordi fita mas 2023-02-14 12:55:19 +01:00
parent 4463c7ee0b
commit 045bf7ff6a
2 changed files with 6 additions and 3 deletions

View File

@ -59,7 +59,6 @@ func GetInvoiceForm(w http.ResponseWriter, r *http.Request, params httprouter.Pa
form := newInvoiceForm(r.Context(), conn, locale, company)
slug := params[0].Value
if slug == "new" {
form.Customer.EmptyLabel = gettext("Select a customer to bill.", locale)
form.Date.Val = time.Now().Format("2006-01-02")
w.WriteHeader(http.StatusOK)
mustRenderNewInvoiceForm(w, r, form)
@ -68,6 +67,8 @@ func GetInvoiceForm(w http.ResponseWriter, r *http.Request, params httprouter.Pa
}
func mustRenderNewInvoiceForm(w http.ResponseWriter, r *http.Request, form *invoiceForm) {
locale := getLocale(r)
form.Customer.EmptyLabel = gettext("Select a customer to bill.", locale)
mustRenderAppTemplate(w, r, "invoices/new.gohtml", form)
}

View File

@ -34,8 +34,10 @@
{{- end }}
<fieldset>
<button name="action" value="products" type="submit">{{( pgettext "Add products" "action" )}}</button>
<button name="action" value="update" type="submit">{{( pgettext "Update" "action" )}}</button>
<button formnovalidate name="action" value="products"
type="submit">{{( pgettext "Add products" "action" )}}</button>
<button formnovalidate name="action" value="update"
type="submit">{{( pgettext "Update" "action" )}}</button>
<button class="primary" name="action" value="add"
type="submit">{{( pgettext "New invoice" "action" )}}</button>
</fieldset>