Skip to content

Commit cf316b1

Browse files
jamiefalcusThemitchell
authored andcommitted
Prevent more than 1 decimal place in height metric
1 parent a9e557e commit cf316b1

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

lung_cancer_screening/questions/forms/metric_height_form.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ def __init__(self, *args, **kwargs):
1111
self.instance.participant = self.participant
1212

1313
self.fields["height"] = DecimalField(
14+
decimal_places=1,
1415
label="Centimetres",
1516
classes="nhsuk-input--width-4",
1617
error_messages={
1718
'required': 'Enter your height',
19+
"max_decimal_places": "Centimetres must be to 1 decimal place, for example 185.5cm",
1820
},
1921
suffix="cm"
2022
)

lung_cancer_screening/questions/tests/unit/forms/test_metric_height_form.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,17 @@ def test_is_invalid(self):
5656
}
5757
)
5858
self.assertFalse(form.is_valid())
59+
60+
def test_is_invalid_with_multiple_decimal_places(self):
61+
form = MetricHeightForm(
62+
participant=self.participant,
63+
instance=self.response_set,
64+
data={
65+
"height": "170.45" # too many decimal places
66+
}
67+
)
68+
self.assertFalse(form.is_valid())
69+
self.assertEqual(
70+
form.errors["height"],
71+
["Centimetres must be to 1 decimal place, for example 185.5cm"]
72+
)

0 commit comments

Comments
 (0)