Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lung_cancer_screening/questions/forms/metric_weight_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@ def __init__(self, *args, **kwargs):
self.instance.participant = self.participant

self.fields["weight_metric"] = DecimalField(
decimal_places=1,
label="Kilograms",
classes="nhsuk-input--width-4",
required=True,
error_messages={
'required': 'Enter your weight',
'max_decimal_places': 'Kilograms must be to 1 decimal place, for example 90.2kgs',
},
suffix="kg"
)

def clean_weight_metric(self):
return self.cleaned_data['weight_metric'] * 10

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,3 +100,17 @@ def test_accepts_maximum_valid_weight(self):
}
)
self.assertTrue(form.is_valid())

def test_is_invalid_with_multiple_decimal_places(self):
form = MetricWeightForm(
participant=self.participant,
instance=self.response_set,
data={
"weight_metric": "100.01" # too many decimal places
}
)
self.assertFalse(form.is_valid())
self.assertEqual(
form.errors["weight_metric"],
["Kilograms must be to 1 decimal place, for example 90.2kgs"]
)
Loading