|
55 | 55 | name="@Model.DayId"
|
56 | 56 | value="@Model.DayValue"
|
57 | 57 | type="text"
|
58 |
| - pattern="[0-9]*" |
59 | 58 | min="1"
|
60 | 59 | max="31"
|
61 | 60 | step="1"
|
|
71 | 70 | name="@Model.MonthId"
|
72 | 71 | value="@Model.MonthValue"
|
73 | 72 | type="text"
|
74 |
| - pattern="[0-9]*" |
75 | 73 | min="1"
|
76 | 74 | max="12"
|
77 | 75 | step="1"
|
|
87 | 85 | name="@Model.YearId"
|
88 | 86 | value="@Model.YearValue"
|
89 | 87 | type="text"
|
90 |
| - pattern="[0-9]*" |
91 | 88 | min="1900"
|
92 | 89 | max="9999"
|
93 | 90 | step="1"
|
94 | 91 | inputmode="numeric"
|
95 | 92 | aria-describedby="date-error" aria-invalid="false" />
|
96 | 93 | </div>
|
97 | 94 | </div>
|
98 |
| - <span id="date-error" class="error-message--margin-bottom-1 nhsuk-error-message" aria-live="polite" style="visibility: hidden;"> |
99 |
| - </span> |
100 | 95 | </div>
|
101 | 96 | </fieldset>
|
102 |
| - <script> |
103 |
| - const fields = [@Model.DayId, @Model.MonthId, @Model.YearId]; |
104 |
| -
|
105 |
| - const errorElement = document.getElementById('date-error'); |
106 |
| - for (let field of fields) { |
107 |
| - const inputElement = document.getElementById(field.id); |
108 |
| -
|
109 |
| - inputElement.addEventListener('input', function (event) { |
110 |
| -
|
111 |
| - if (event.inputType === 'deleteContentBackward') { |
112 |
| - return; |
113 |
| - } |
114 |
| -
|
115 |
| - const value = event.data; |
116 |
| - const min = parseInt(inputElement.getAttribute('min')); |
117 |
| - const max = parseInt(inputElement.getAttribute('max')); |
118 |
| -
|
119 |
| - inputElement.setAttribute('aria-invalid', 'false'); |
120 |
| - errorElement.textContent = ''; |
121 |
| - errorElement.style.visibility = 'hidden'; |
122 |
| -
|
123 |
| - setTimeout(function () { |
124 |
| - if (value < 1 || value > max || !value.match(/^[0-9]*$/)) { |
125 |
| - inputElement.value = inputElement.value.slice(0, -1) + 1; |
126 |
| - inputElement.value = inputElement.value.slice(0, -1); |
127 |
| - inputElement.setAttribute('aria-invalid', 'true'); |
128 |
| - errorElement.textContent = `Invalid input. Please enter a number between ${min} and ${max}.`; |
129 |
| - errorElement.style.visibility = 'visible'; |
130 |
| - } |
131 |
| - }, 0); |
132 |
| - }); |
133 |
| - } |
134 |
| - </script> |
135 | 97 | </div>
|
0 commit comments