From d9179a9cb7386de09a005433afb2245b68ff5693 Mon Sep 17 00:00:00 2001 From: Neil Kakkar Date: Tue, 17 Oct 2023 14:54:16 +0100 Subject: [PATCH] fix(surveys): add listener to 0th element --- src/extensions/surveys.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/extensions/surveys.ts b/src/extensions/surveys.ts index 6f54eb379..a99ca5924 100644 --- a/src/extensions/surveys.ts +++ b/src/extensions/surveys.ts @@ -549,8 +549,9 @@ export const createRatingsPopup = (posthog: PostHog, survey: Survey, question: R }) } formElement.getElementsByClassName('rating-options')[0].insertAdjacentElement('afterbegin', ratingOptionsElement) - for (const x of Array(question.scale).keys()) { - const ratingEl = formElement.getElementsByClassName(`rating_${x + 1}`)[0] + const allElements = question.scale === 10 ? [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10] : [1, 2, 3, 4, 5] + for (const x of allElements) { + const ratingEl = formElement.getElementsByClassName(`rating_${x}`)[0] ratingEl.addEventListener('click', (e) => { e.preventDefault() for (const activeRatingEl of formElement.getElementsByClassName('rating-active')) {