Skip to content

Commit a2e8e80

Browse files
committed
proposals - rating-dialog.djhtml function for adding and removing active class for stars
1 parent a3b3b23 commit a2e8e80

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

srv/templates/proposals/rating-dialog.djhtml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,21 @@
118118

119119
eDiv_dialogContainer.insertBefore(eDiv_ratingWrapper, elm.nextSibling)
120120
}
121+
122+
function changeStar(e, elm) {
123+
const parent = e.target.parentElement
124+
const childrenList = Array.prototype.slice.call(parent.children)
125+
const clickedOn = e.target.getAttribute('data-value')
126+
127+
for(let i=0; i<childrenList.length; i++) {
128+
childrenList[i].classList.remove('active')
129+
if(i < clickedOn) {
130+
childrenList[i].classList.add('active')
131+
}
132+
}
133+
134+
const activeStar = Array.from(parent.children).filter(span => span.classList.contains('active')).length
135+
const questionIndex = Array.from(eDiv_dialogContainer.querySelectorAll('p')).indexOf(elm)
136+
ratings[questionIndex] = activeStar
137+
}
121138
</script>

0 commit comments

Comments
 (0)