diff --git a/portmap/core/forms.py b/portmap/core/forms.py index 5ba62e1..d1ae0b1 100644 --- a/portmap/core/forms.py +++ b/portmap/core/forms.py @@ -4,11 +4,10 @@ from .models import User, UseCaseFeedback -# The included RadioSelect widget wraps the input element inside of a label, -# which makes it difficult to style the label based on the input's checked state. -# This custom widget structures the label and input as siblings instead. -class UnwrappedRadioSelect(forms.RadioSelect): - option_template_name = "forms/widgets/unwrapped_radio_option.html" +# Renders the radio option as a Lucide icon +class IconRadioSelect(forms.RadioSelect): + option_template_name = "forms/widgets/icon_radio_option.html" + class CustomFormRenderer(TemplatesSetting): form_template_name = "forms/custom.html" @@ -33,6 +32,7 @@ class Meta: model = User fields = ("first_name", "last_name") + class QueryIndexForm(forms.Form): data_type_choices = (('error', 'data missing')) datatype = forms.ChoiceField(label="Select Type to transfer", choices=data_type_choices, required=True) @@ -46,14 +46,16 @@ def __init__(self, data, datatypes=None): self.fields['datadest'].disabled = True self.label_suffix = ' ' + class ArticleFeedbackForm(forms.Form): - CHOICES = [('happy', 'Yes'), - ('sad', 'No')] - reaction = forms.ChoiceField(label="Did this article help?", widget=UnwrappedRadioSelect, choices=CHOICES) + CHOICES = [('happy', 'smile'), + ('sad', 'frown')] + reaction = forms.ChoiceField(label="Did this article help?", widget=IconRadioSelect, choices=CHOICES) explanation = forms.CharField(widget=forms.Textarea, required=False, label="What is your use case? What would make this article better?") + class UseCaseFeedbackForm(forms.ModelForm): class Meta: model = UseCaseFeedback diff --git a/static/js/article.js b/static/js/article.js index d12e49c..f2411c1 100644 --- a/static/js/article.js +++ b/static/js/article.js @@ -1,28 +1,10 @@ -/* global lucide */ - (function () { - function lucideElement(name) { - const element = document.createElement('i'); - element.setAttribute('data-lucide', name); - return element; - } - document.addEventListener('DOMContentLoaded', function () { const happyButton = document.getElementById('id_reaction_0').nextElementSibling; const sadButton = document.getElementById('id_reaction_1').nextElementSibling; - // replaces "yes" string with smily face - happyButton.innerHTML = ''; - happyButton.appendChild(lucideElement('smile')); - - // replaces "no" with frown - sadButton.innerHTML = ''; - sadButton.appendChild(lucideElement('frown')); - - lucide.createIcons(); - const explanationText = document.getElementById('id_explanation'); explanationText.hidden = true; const explanationLabel = diff --git a/templates/_base.html b/templates/_base.html index 17e97f7..1d88e9f 100644 --- a/templates/_base.html +++ b/templates/_base.html @@ -10,7 +10,24 @@