Skip to content

Commit 5fa813c

Browse files
jamiefalcusThemitchell
authored andcommitted
Add sufix to decimal field
1 parent 3c68d2f commit 5fa813c

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

lung_cancer_screening/nhsuk_forms/decimal_field.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ def __init__(
1111
):
1212
kwargs["template_name"] = "input.jinja"
1313

14+
self.suffix = kwargs.pop("suffix", None)
1415
self.hint = hint
1516
self.classes = classes
1617
self.label_classes = label_classes

lung_cancer_screening/nhsuk_forms/jinja2/input.jinja

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
"hint": {
1616
"text": unbound_field.hint
1717
} if unbound_field.hint,
18+
"suffix": unbound_field.suffix if unbound_field.suffix,
1819
"id": field.auto_id,
1920
"name": field.html_name,
2021
"value": field.value() or "",
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from django.test import TestCase
2+
from django.forms import Form
3+
from ...decimal_field import DecimalField
4+
5+
6+
class TestDecimalField(TestCase):
7+
def test_renders_nhs_input(self):
8+
class TestForm(Form):
9+
field = DecimalField(label="Abc", initial=1, max_value=10)
10+
self.assertHTMLEqual(
11+
TestForm()["field"].as_field_group(),
12+
"""
13+
<div class="nhsuk-form-group">
14+
<label class="nhsuk-label" for="id_field">
15+
Abc
16+
</label><input class="nhsuk-input" id="id_field" name="field" type="number" value="1">
17+
</div>
18+
""",
19+
)
20+
21+
def test_renders_nhs_input_with_suffix(self):
22+
class TestForm(Form):
23+
field = DecimalField(label="Abc", initial=1, max_value=10, suffix="cm")
24+
print(TestForm()["field"].as_field_group())
25+
self.assertHTMLEqual(
26+
TestForm()["field"].as_field_group(),
27+
"""
28+
<div class="nhsuk-form-group">
29+
<label class="nhsuk-label" for="id_field">
30+
Abc
31+
</label>
32+
<div class="nhsuk-input__wrapper">
33+
<input class="nhsuk-input" id="id_field" name="field" type="number" value="1">
34+
<div class="nhsuk-input__suffix" aria-hidden="true">cm</div>
35+
</div>
36+
</>
37+
""",
38+
)
39+

0 commit comments

Comments
 (0)