Sith/pedagogy/templates/pedagogy/starlist.jinja

41 lines
1.3 KiB
Django/Jinja

<div>
{# <input name="{{ widget.name }}" id="{{ widget.name }}" hidden type="number" {% include "django/forms/widgets/attrs.html" %}></input> #}
<style>
.checked{
color : orange;
}
.unchecked{
color : gray;
}
.star input[type="radio"]{
display : none;
}
.star{
display: inline;
}
</style>
{% for i in i|rjust:5 %}
<label class="star">
<input type="radio" name="{{ widget.name }}" value="{{ forloop.counter0 }}" onclick='
var stars = document.getElementsByClassName("{{ widget.name }}");
// console.log(Array.from(this.parentNode.parentNode.children).filter(el => el.className == "star"));
for (var i = 0; i < 5; i++){
console.log(i);
var attrs = stars[i].getAttribute("class");
attrs = attrs.replace("unchecked", "");
attrs = attrs.replace("checked", "");
if (i > {{ forloop.counter0 }}){
stars[i].setAttribute("class", attrs + " unchecked");
} else {
stars[i].setAttribute("class", attrs + " checked");
}
}
'>
<i class="{{ widget.name }} fa fa-star unchecked"></i>
</label>
{% endfor %}
</div>