From a9afc385e92fea7b4e9593c1373127e324f9226a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=9D=E7=91=AA=E8=B2=93?= Date: Fri, 24 Mar 2023 06:46:22 +0800 Subject: [PATCH] Added the "baseCode" getter to the JavaScript AccountForm form, and removed the "baseCode" parameter from the onOpen method of the BaseAccountSelector class. It can retrieve the base code directly from the parent account form now. --- src/accounting/static/js/account-form.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/accounting/static/js/account-form.js b/src/accounting/static/js/account-form.js index 310bd13..a199764 100644 --- a/src/accounting/static/js/account-form.js +++ b/src/accounting/static/js/account-form.js @@ -114,10 +114,19 @@ class AccountForm { }; this.#baseControl.onclick = () => { this.#baseControl.classList.add("accounting-not-empty"); - this.#baseAccountSelector.onOpen(this.#baseCode.value); + this.#baseAccountSelector.onOpen(); }; } + /** + * Returns the base code. + * + * @return {string|null} + */ + get baseCode() { + return this.#baseCode.value === ""? null: this.#baseCode.value; + } + /** * The callback when the base account selector is closed. * @@ -308,15 +317,14 @@ class BaseAccountSelector { /** * The callback when the base account selector is shown. * - * @param baseCode {string} the active base code */ - onOpen(baseCode) { + onOpen() { this.#query.value = ""; this.#filterOptions(); for (const option of this.#options) { - option.setActive(option.code === baseCode); + option.setActive(option.code === this.form.baseCode); } - if (baseCode === "") { + if (this.form.baseCode === null) { this.#clearButton.classList.add("btn-secondary") this.#clearButton.classList.remove("btn-danger"); this.#clearButton.disabled = true;