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.

This commit is contained in:
依瑪貓 2023-03-24 06:46:22 +08:00
parent a8be739ec7
commit a9afc385e9

View File

@ -114,10 +114,19 @@ class AccountForm {
}; };
this.#baseControl.onclick = () => { this.#baseControl.onclick = () => {
this.#baseControl.classList.add("accounting-not-empty"); 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. * The callback when the base account selector is closed.
* *
@ -308,15 +317,14 @@ class BaseAccountSelector {
/** /**
* The callback when the base account selector is shown. * The callback when the base account selector is shown.
* *
* @param baseCode {string} the active base code
*/ */
onOpen(baseCode) { onOpen() {
this.#query.value = ""; this.#query.value = "";
this.#filterOptions(); this.#filterOptions();
for (const option of this.#options) { 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.add("btn-secondary")
this.#clearButton.classList.remove("btn-danger"); this.#clearButton.classList.remove("btn-danger");
this.#clearButton.disabled = true; this.#clearButton.disabled = true;