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

View File

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