Coverage for benefits / core / widgets.py: 74%
25 statements
« prev ^ index » next coverage.py v7.13.4, created at 2026-02-13 19:35 +0000
« prev ^ index » next coverage.py v7.13.4, created at 2026-02-13 19:35 +0000
1"""
2The core application: Helper form widgets.
3"""
5import copy
7from django.forms import widgets
10class FormControlTextInput(widgets.TextInput):
11 """A styled text input."""
13 def __init__(self, pattern=None, placeholder=None, **kwargs):
14 super().__init__(**kwargs)
16 self.attrs.update({"class": "form-control"})
17 if pattern: 17 ↛ 18line 17 didn't jump to line 18 because the condition on line 17 was never true
18 self.attrs.update({"pattern": pattern})
19 if placeholder:
20 self.attrs.update({"placeholder": placeholder})
23class FlowRadioSelect(widgets.RadioSelect):
24 """A radio select input styled for the Enrollment Flow."""
26 template_name = "core/widgets/flow-radio-select.html"
27 option_template_name = "core/widgets/flow-radio-select-option.html"
29 def __init__(self, selection_label_templates=(), *args, **kwargs):
30 super().__init__(*args, **kwargs)
31 self.selection_label_templates = list(selection_label_templates)
33 def __deepcopy__(self, memo):
34 obj = super().__deepcopy__(memo)
35 obj.selection_label_templates = copy.copy(self.selection_label_templates)
36 return obj
38 def create_option(self, name, value, label, selected, index, subindex, attrs):
39 option = super().create_option(name, value, label, selected, index, subindex, attrs)
40 # this implementation does not support groups from ChoiceWidget.optgroups
41 if value in self.selection_label_templates:
42 option.update({"selection_label_template": self.selection_label_templates[value]})
44 return option