Revised the summary helper so that when the summary is changed with the tag changed, the on-change callback is run to check the tag button status.

This commit is contained in:
依瑪貓 2023-03-04 00:18:54 +08:00
parent 73f7d14e7b
commit f41db78831

View File

@ -462,13 +462,23 @@ class TagTabPlane extends TabPlane {
this.initializeTagButtons(); this.initializeTagButtons();
const tabPlane = this; const tabPlane = this;
this.tag.onchange = function () { this.tag.onchange = function () {
tabPlane.tag.value = tabPlane.tag.value.trim(); tabPlane.onTagChange();
tabPlane.updateSummary();
};
}
/**
* The callback when the tag input is changed
*
*/
onTagChange() {
this.tag.value = this.tag.value.trim();
let isMatched = false; let isMatched = false;
for (const tagButton of tabPlane.tagButtons) { for (const tagButton of this.tagButtons) {
if (tagButton.dataset.value === tabPlane.tag.value) { if (tagButton.dataset.value === this.tag.value) {
tagButton.classList.remove("btn-outline-primary"); tagButton.classList.remove("btn-outline-primary");
tagButton.classList.add("btn-primary"); tagButton.classList.add("btn-primary");
tabPlane.editor.filterSuggestedAccounts(tagButton); this.editor.filterSuggestedAccounts(tagButton);
isMatched = true; isMatched = true;
} else { } else {
tagButton.classList.remove("btn-primary"); tagButton.classList.remove("btn-primary");
@ -476,11 +486,9 @@ class TagTabPlane extends TabPlane {
} }
} }
if (!isMatched) { if (!isMatched) {
tabPlane.editor.filterSuggestedAccounts(null); this.editor.filterSuggestedAccounts(null);
} }
tabPlane.updateSummary(); this.validateTag();
tabPlane.validateTag();
};
} }
/** /**
@ -618,7 +626,10 @@ class GeneralTagTab extends TagTabPlane {
if (found === null) { if (found === null) {
return false; return false;
} }
if (this.tag.value !== found[1]) {
this.tag.value = found[1]; this.tag.value = found[1];
this.onTagChange();
}
for (const tagButton of this.tagButtons) { for (const tagButton of this.tagButtons) {
if (tagButton.dataset.value === this.tag.value) { if (tagButton.dataset.value === this.tag.value) {
tagButton.classList.remove("btn-outline-primary"); tagButton.classList.remove("btn-outline-primary");
@ -776,7 +787,10 @@ class GeneralTripTab extends TagTabPlane {
if (found === null) { if (found === null) {
return false; return false;
} }
if (this.tag.value !== found[1]) {
this.tag.value = found[1]; this.tag.value = found[1];
this.onTagChange();
}
this.#from.value = found[2]; this.#from.value = found[2];
for (const directionButton of this.#directionButtons) { for (const directionButton of this.#directionButtons) {
if (directionButton.dataset.arrow === found[3]) { if (directionButton.dataset.arrow === found[3]) {
@ -967,7 +981,10 @@ class BusTripTab extends TagTabPlane {
if (found === null) { if (found === null) {
return false; return false;
} }
if (this.tag.value !== found[1]) {
this.tag.value = found[1]; this.tag.value = found[1];
this.onTagChange();
}
this.#route.value = found[2]; this.#route.value = found[2];
this.#from.value = found[3]; this.#from.value = found[3];
this.#to.value = found[4]; this.#to.value = found[4];