Skip to content

Commit 4d78fa8

Browse files
authored
Merge pull request #152 from NHSDigital/handle-incorrect-day-month-year-validation-error-for-dob
Use generic valid date error for dob upper and lower bound validations
2 parents 993e31f + 33d77a8 commit 4d78fa8

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-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: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ def __init__(self, *args, **kwargs):
1010
super().__init__(*args, **kwargs)
1111
self.instance.participant = self.participant
1212

13+
invalid_error_message = 'Date of birth must be a real date'
1314
self.fields["date_of_birth"] = SplitDateField(
1415
max_value=date.today(),
1516
required=True,
@@ -20,7 +21,9 @@ def __init__(self, *args, **kwargs):
2021
error_messages={
2122
'required': 'Enter your date of birth',
2223
'incomplete': 'Enter your full date of birth',
23-
'invalid': 'Date of birth must be a real date'
24+
'invalid': invalid_error_message,
25+
'day_bounds': invalid_error_message,
26+
'month_bounds': invalid_error_message
2427
}
2528
)
2629

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)