The view mistakenly assumed that the button for showing the results was always present. This caused a javascript error for guests or for users who could only see the result.
}
});
- if (this.canViewResults) {
- this.resultsView = new Results(this);
+ const button = this.element.querySelector<HTMLButtonElement>(".showResultsButton");
+ if (this.canViewResults && button !== null) {
+ this.resultsView = new Results(this, button);
}
if (this.canVote) {
private readonly pollManager: Poll;
private readonly button: HTMLButtonElement;
- public constructor(manager: Poll) {
+ public constructor(manager: Poll, button: HTMLButtonElement) {
this.pollManager = manager;
-
- const button = this.pollManager.getElement().querySelector<HTMLButtonElement>(".showResultsButton");
-
- if (!button) {
- throw new Error(`Could not find button with selector ".showResultsButton" for poll "${this.pollManager.pollId}"`);
- }
-
this.button = button;
this.button.addEventListener("click", async (event) => {
this.views.set(element.dataset.key, element);
}
});
- if (this.canViewResults) {
- this.resultsView = new Results_1.default(this);
+ const button = this.element.querySelector(".showResultsButton");
+ if (this.canViewResults && button !== null) {
+ this.resultsView = new Results_1.default(this, button);
}
if (this.canVote) {
this.voteView = new Vote_1.default(this);
exports.Results = void 0;
Ajax = tslib_1.__importStar(Ajax);
class Results {
- constructor(manager) {
+ constructor(manager, button) {
this.pollManager = manager;
- const button = this.pollManager.getElement().querySelector(".showResultsButton");
- if (!button) {
- throw new Error(`Could not find button with selector ".showResultsButton" for poll "${this.pollManager.pollId}"`);
- }
this.button = button;
this.button.addEventListener("click", async (event) => {
if (event) {