Skip to content

Commit 23c869e

Browse files
TD-4624 format the error message
1 parent 4f653d9 commit 23c869e

File tree

3 files changed

+47
-12
lines changed

3 files changed

+47
-12
lines changed

DigitalLearningSolutions.Web/Helpers/ProfessionalRegistrationNumberHelper.cs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
{
33

44
using Microsoft.AspNetCore.Mvc.ModelBinding;
5+
using System.Text;
56
using System.Text.RegularExpressions;
67

78
public class ProfessionalRegistrationNumberHelper
@@ -53,14 +54,16 @@ public static void ValidateProfessionalRegistrationNumber(
5354
public static string GetProfessionalRegistrationNumberErrorMessage()
5455
{
5556
return @"The format you entered isn’t recognised. Please check and try again.
56-
Valid formats include
57-
7 digits - example, 1234567
58-
1-2 letters followed by 6 digits - example, AB123456
59-
‘P’ followed by 5-6 digits - example, P12345, P123456
60-
‘C’ or ‘P’ followed by 6 digits - example, C123456, P123456
61-
Optional letter followed by 5-6 digits - example, A12345, B123456
62-
‘L’ followed by 4-6 digits - example, L1234, L123456
63-
2 digits, hyphen, then 4-5 alphanumeric characters - example, 12-AB123";
57+
<br>Valid formats include:
58+
<ul>
59+
<li>7 digits - example, 1234567</li>
60+
<li>1–2 letters followed by 6 digits - example, AB123456</li>
61+
<li>‘P’ followed by 5–6 digits - example, P12345, P123456</li>
62+
<li>‘C’ or ‘P’ followed by 6 digits - example, C123456, P123456</li>
63+
<li>Optional letter followed by 5–6 digits - example, A12345, B123456</li>
64+
<li>‘L’ followed by 4–6 digits - example, L1234, L123456</li>
65+
<li>2 digits, hyphen, then 4–5 alphanumeric characters - example, 12-AB123</li>
66+
</ul>";
6467
}
6568
}
6669
}

DigitalLearningSolutions.Web/Views/Shared/_EditRegistrationNumber.cshtml

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717

1818
var subject = Model.IsSelfRegistrationOrEdit ? "you" : "they";
1919
var capitalisedSubject = Model.IsSelfRegistrationOrEdit ? "You" : "They";
20+
var professionalRegistrationNumberError = ViewData.ModelState["ProfessionalRegistrationNumber"]?.Errors.FirstOrDefault()?.ErrorMessage;
21+
if (ViewData.ModelState.ContainsKey("ProfessionalRegistrationNumber"))
22+
{
23+
ViewData.ModelState["ProfessionalRegistrationNumber"].Errors.Clear();
24+
}
2025
}
2126

2227
<input type="hidden" asp-for="IsSelfRegistrationOrEdit" />
@@ -53,7 +58,7 @@
5358
No
5459
</label>
5560
</div>
56-
61+
5762
<div class="nhsuk-radios__item">
5863
<input name="@nameof(Model.HasProfessionalRegistrationNumber)"
5964
class="nhsuk-radios__input"
@@ -66,9 +71,16 @@
6671
Yes
6772
</label>
6873
</div>
69-
<div class="nhsuk-radios__conditional @(optionYesSelected ? " " : " nhsuk-radios__conditional--hidden") @(professionalRegNumberErrorHasOccurred ? "form-group-wrapper--error" : "" )"
74+
<div class="nhsuk-radios__conditional @(optionYesSelected ? " " : " nhsuk-radios__conditional--hidden") @(professionalRegNumberErrorHasOccurred ? "form-group-wrapper--error" : "")"
7075
id="@professionalRegConditionalId">
71-
<vc:text-input asp-for="@nameof(Model.ProfessionalRegistrationNumber)"
76+
@if (professionalRegistrationNumberError != null)
77+
{
78+
<span class="nhsuk-error-message" id="ProfessionalRegistrationNumber-error">
79+
<span class="nhsuk-u-visually-hidden">Error:</span>
80+
@Html.Raw(professionalRegistrationNumberError)
81+
</span>
82+
}
83+
<vc:text-input asp-for="@nameof(Model.ProfessionalRegistrationNumber)"
7284
label="Professional Registration Number"
7385
populate-with-current-value="true"
7486
type="text"

DigitalLearningSolutions.Web/Views/TrackingSystem/Delegates/EditDelegate/Index.cshtml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
<div class="nhsuk-grid-column-full">
1616
@if (errorHasOccurred)
1717
{
18-
<vc:error-summary order-of-property-names="@(new[] {
18+
var professionalRegistrationNumberError = ViewData.ModelState["ProfessionalRegistrationNumber"]?.Errors.FirstOrDefault();
19+
if (professionalRegistrationNumberError == null)
20+
{
21+
<vc:error-summary order-of-property-names="@(new[] {
1922
nameof(Model.FirstName),
2023
nameof(Model.LastName),
2124
nameof(Model.CentreSpecificEmail),
@@ -28,6 +31,23 @@
2831
nameof(Model.Answer4),
2932
nameof(Model.Answer5),
3033
nameof(Model.Answer6) })" />
34+
}
35+
if (professionalRegistrationNumberError != null)
36+
{
37+
<div class="nhsuk-error-summary" aria-labelledby="error-summary-title" role="alert" tabindex="-1">
38+
<h2 class="nhsuk-error-summary__title" id="error-summary-title">
39+
There is a problem
40+
</h2>
41+
<div class="nhsuk-error-summary__body">
42+
<span class="nhsuk-error-message" id="ProfessionalRegistrationNumber-error">
43+
<span class="nhsuk-u-visually-hidden">Error:</span> <span class="nhsuk-error-message" id="ProfessionalRegistrationNumber-error">
44+
<span class="nhsuk-u-visually-hidden">Error:</span>
45+
@Html.Raw(professionalRegistrationNumberError.ErrorMessage)
46+
</span>
47+
</span>
48+
</div>
49+
</div>
50+
}
3151
}
3252

3353
<h1 class="nhsuk-heading-xl">Edit delegate details</h1>

0 commit comments

Comments
 (0)