Trigger a recompute when price, quantity, discount, or vat changes

I had to add the correct change event to the select in order for this to
work, too; in tags it was already done, i and did something very
similar.
This commit is contained in:
jordi fita mas 2023-04-28 00:22:28 +02:00
parent 86ccbbe830
commit d941adcdfe
2 changed files with 13 additions and 3 deletions

View File

@ -753,6 +753,7 @@ type invoiceProductForm struct {
} }
func newInvoiceProductForm(index int, company *Company, locale *Locale, taxOptions []*SelectOption) *invoiceProductForm { func newInvoiceProductForm(index int, company *Company, locale *Locale, taxOptions []*SelectOption) *invoiceProductForm {
triggerRecompute := template.HTMLAttr(`data-hx-on="change: this.dispatchEvent(new CustomEvent('recompute', {bubbles: true}))"`)
form := &invoiceProductForm{ form := &invoiceProductForm{
locale: locale, locale: locale,
company: company, company: company,
@ -790,6 +791,7 @@ func newInvoiceProductForm(index int, company *Company, locale *Locale, taxOptio
Type: "number", Type: "number",
Required: true, Required: true,
Attributes: []template.HTMLAttr{ Attributes: []template.HTMLAttr{
triggerRecompute,
`min="0"`, `min="0"`,
template.HTMLAttr(fmt.Sprintf(`step="%v"`, company.MinCents())), template.HTMLAttr(fmt.Sprintf(`step="%v"`, company.MinCents())),
}, },
@ -799,6 +801,7 @@ func newInvoiceProductForm(index int, company *Company, locale *Locale, taxOptio
Type: "number", Type: "number",
Required: true, Required: true,
Attributes: []template.HTMLAttr{ Attributes: []template.HTMLAttr{
triggerRecompute,
`min="0"`, `min="0"`,
}, },
}, },
@ -807,6 +810,7 @@ func newInvoiceProductForm(index int, company *Company, locale *Locale, taxOptio
Type: "number", Type: "number",
Required: true, Required: true,
Attributes: []template.HTMLAttr{ Attributes: []template.HTMLAttr{
triggerRecompute,
`min="0"`, `min="0"`,
`max="100"`, `max="100"`,
}, },
@ -815,6 +819,9 @@ func newInvoiceProductForm(index int, company *Company, locale *Locale, taxOptio
Label: pgettext("input", "Taxes", locale), Label: pgettext("input", "Taxes", locale),
Multiple: true, Multiple: true,
Options: taxOptions, Options: taxOptions,
Attributes: []template.HTMLAttr{
triggerRecompute,
},
}, },
} }
form.Rename() form.Rename()

View File

@ -197,9 +197,12 @@ class Multiselect extends HTMLDivElement {
if (!option) { if (!option) {
return; return;
} }
option.selected = selected; if (option.selected !== selected) {
this.toSearch = this.search.value = ''; option.selected = selected;
this.rebuild(); this.select.dispatchEvent(new Event('change', {bubbles: true}));
this.toSearch = this.search.value = '';
this.rebuild();
}
} }
selectHighlighted() { selectHighlighted() {