Skip to content

Commit 926aa84

Browse files
committed
USe generic valid date error for dob bound validations
1 parent a27206b commit 926aa84

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

lung_cancer_screening/nhsuk_forms/split_date_field.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ def __init__(self, *args, **kwargs):
7171
self.label_is_page_heading = kwargs.pop("label_is_page_heading", False)
7272
self.hint = kwargs.pop("hint", None)
7373

74-
day_bounds_error = gettext("Day should be between 1 and 31.")
75-
month_bounds_error = gettext("Month should be between 1 and 12.")
74+
day_bounds_error = kwargs.get("error_messages", {}).pop("day_bounds", gettext("Day should be between 1 and 31."))
75+
month_bounds_error = kwargs.get("error_messages", {}).pop("month_bounds", gettext("Month should be between 1 and 12."))
7676
year_bounds_error = gettext(
7777
"Year should be between %(min_year)s and %(max_year)s."
7878
) % {"min_year": min_value.year, "max_year": max_value.year}

lung_cancer_screening/questions/forms/date_of_birth_form.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ def __init__(self, *args, **kwargs):
2020
error_messages={
2121
'required': 'Enter your date of birth.',
2222
'incomplete': 'Enter your full date of birth.',
23-
'invalid': 'Date of birth must be a real date.'
23+
'invalid': 'Date of birth must be a real date.',
24+
'day_bounds': 'Date of birth must be a real date.',
25+
'month_bounds': 'Date of birth must be a real date.'
2426
}
2527
)
2628

tests/features/validation_errors.feature

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ Feature: Validation errors
55
And I submit the form
66
Then I am on "/date-of-birth"
77
And I see a form error "Enter your date of birth."
8+
When I fill in and submit my date of birth with "51-01-2001"
9+
Then I am on "/date-of-birth"
10+
And I see a form error "Date of birth must be a real date."
11+
When I fill in and submit my date of birth with "01-13-2001"
12+
Then I am on "/date-of-birth"
13+
And I see a form error "Date of birth must be a real date."
14+
When I fill in and submit my date of birth with "31-02-2001"
15+
Then I am on "/date-of-birth"
16+
And I see a form error "Date of birth must be a real date."
817

918
Scenario: Height form errors
1019
Given I have started the questionnaire

0 commit comments

Comments
 (0)