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
4 changes: 2 additions & 2 deletions lung_cancer_screening/nhsuk_forms/split_date_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ def __init__(self, *args, **kwargs):
self.label_is_page_heading = kwargs.pop("label_is_page_heading", False)
self.hint = kwargs.pop("hint", None)

day_bounds_error = gettext("Day should be between 1 and 31.")
month_bounds_error = gettext("Month should be between 1 and 12.")
day_bounds_error = kwargs.get("error_messages", {}).pop("day_bounds", gettext("Day should be between 1 and 31."))
month_bounds_error = kwargs.get("error_messages", {}).pop("month_bounds", gettext("Month should be between 1 and 12."))
year_bounds_error = gettext(
"Year should be between %(min_year)s and %(max_year)s."
) % {"min_year": min_value.year, "max_year": max_value.year}
Expand Down
5 changes: 4 additions & 1 deletion lung_cancer_screening/questions/forms/date_of_birth_form.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self.instance.participant = self.participant

invalid_error_message = 'Date of birth must be a real date'
self.fields["date_of_birth"] = SplitDateField(
max_value=date.today(),
required=True,
Expand All @@ -20,7 +21,9 @@ def __init__(self, *args, **kwargs):
error_messages={
'required': 'Enter your date of birth',
'incomplete': 'Enter your full date of birth',
'invalid': 'Date of birth must be a real date'
'invalid': invalid_error_message,
'day_bounds': invalid_error_message,
'month_bounds': invalid_error_message
}
)

Expand Down
9 changes: 9 additions & 0 deletions tests/features/validation_errors.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@ Feature: Validation errors
And I submit the form
Then I am on "/date-of-birth"
And I see a form error "Enter your date of birth"
When I fill in and submit my date of birth with "51-01-2001"
Then I am on "/date-of-birth"
And I see a form error "Date of birth must be a real date"
When I fill in and submit my date of birth with "01-13-2001"
Then I am on "/date-of-birth"
And I see a form error "Date of birth must be a real date"
When I fill in and submit my date of birth with "31-02-2001"
Then I am on "/date-of-birth"
And I see a form error "Date of birth must be a real date"

Scenario: Height form errors
Given I have started the questionnaire
Expand Down
Loading