diff --git a/lung_cancer_screening/nhsuk_forms/split_date_field.py b/lung_cancer_screening/nhsuk_forms/split_date_field.py index 6ea21f1f..c755bad3 100644 --- a/lung_cancer_screening/nhsuk_forms/split_date_field.py +++ b/lung_cancer_screening/nhsuk_forms/split_date_field.py @@ -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} diff --git a/lung_cancer_screening/questions/forms/date_of_birth_form.py b/lung_cancer_screening/questions/forms/date_of_birth_form.py index 047ffea9..02a60907 100644 --- a/lung_cancer_screening/questions/forms/date_of_birth_form.py +++ b/lung_cancer_screening/questions/forms/date_of_birth_form.py @@ -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, @@ -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 } ) diff --git a/tests/features/validation_errors.feature b/tests/features/validation_errors.feature index f7234db1..e13f9210 100644 --- a/tests/features/validation_errors.feature +++ b/tests/features/validation_errors.feature @@ -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