Skip to content

Commit

Permalink
fix: make it so clicking off Login.gov help modal doesn't select input
Browse files Browse the repository at this point in the history
  • Loading branch information
angela-tran committed Jul 12, 2023
1 parent 4743098 commit a3854df
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
5 changes: 3 additions & 2 deletions benefits/core/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ class VerifierRadioSelect(widgets.RadioSelect):
template_name = "core/widgets/verifier_radio_select.html"
option_template_name = "core/widgets/verifier_radio_select_option.html"

def __init__(self, selection_label_templates=(), *args, **kwargs):
def __init__(self, selection_label_templates=(), csp_nonce=None, *args, **kwargs):
super().__init__(*args, **kwargs)
self.selection_label_templates = list(selection_label_templates)
self.csp_nonce = csp_nonce

def __deepcopy__(self, memo):
obj = super().__deepcopy__(memo)
Expand All @@ -37,6 +38,6 @@ def create_option(self, name, value, label, selected, index, subindex, attrs):
option = super().create_option(name, value, label, selected, index, subindex, attrs)
# this implementation does not support groups from ChoiceWidget.optgroups
if value in self.selection_label_templates:
option.update({"selection_label_template": self.selection_label_templates[value]})
option.update({"selection_label_template": self.selection_label_templates[value], "csp_nonce": self.csp_nonce})

return option
3 changes: 2 additions & 1 deletion benefits/eligibility/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class EligibilityVerifierSelectionForm(forms.Form):
# sets label to empty string so the radio_select template can override the label style
submit_value = _("eligibility.buttons.choose")

def __init__(self, agency: models.TransitAgency, *args, **kwargs):
def __init__(self, agency: models.TransitAgency, csp_nonce, *args, **kwargs):
super().__init__(*args, **kwargs)
verifiers = agency.eligibility_verifiers.all()

Expand All @@ -32,6 +32,7 @@ def __init__(self, agency: models.TransitAgency, *args, **kwargs):
# therefore set to None
self.fields["verifier"].choices = [(v.id, None) for v in verifiers]
self.fields["verifier"].widget.selection_label_templates = {v.id: v.selection_label_template for v in verifiers}
self.fields["verifier"].widget.csp_nonce = csp_nonce

def clean(self):
if not recaptcha.verify(self.data):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,11 @@
</button>

{% include "eligibility/includes/modal--senior-help.html" with id="login-gov-help" %}

<script nonce="{{ widget.csp_nonce }}">
const modal = document.getElementById("login-gov-help");
modal.addEventListener('click', function (event) {
event.preventDefault();
});
</script>
{% endblock description %}
2 changes: 1 addition & 1 deletion benefits/eligibility/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def index(request, agency=None):
title=_("eligibility.pages.index.title"),
headline=_("eligibility.pages.index.headline"),
paragraphs=[intro],
forms=forms.EligibilityVerifierSelectionForm(agency=agency),
forms=forms.EligibilityVerifierSelectionForm(agency=agency, csp_nonce=request.csp_nonce),
)

ctx = page.context_dict()
Expand Down

0 comments on commit a3854df

Please sign in to comment.