Skip to content

Commit 68411ff

Browse files
Merge pull request #37 from TechnologyEnhancedLearning/Develop/Fixes/TD-4180-DIG409-An-error-is-present-and-correct-however-is-not-programmatically-associatedwith-field
TD-4180: Moved client side validations to server side.
2 parents ed6e8ef + 06252b9 commit 68411ff

File tree

2 files changed

+1
-54
lines changed

2 files changed

+1
-54
lines changed

NHSUKViewComponents.Web/Views/Shared/Components/DateInput/Default.cshtml

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@
5555
name="@Model.DayId"
5656
value="@Model.DayValue"
5757
type="text"
58-
pattern="[0-9]*"
5958
min="1"
6059
max="31"
6160
step="1"
@@ -71,7 +70,6 @@
7170
name="@Model.MonthId"
7271
value="@Model.MonthValue"
7372
type="text"
74-
pattern="[0-9]*"
7573
min="1"
7674
max="12"
7775
step="1"
@@ -87,49 +85,13 @@
8785
name="@Model.YearId"
8886
value="@Model.YearValue"
8987
type="text"
90-
pattern="[0-9]*"
9188
min="1900"
9289
max="9999"
9390
step="1"
9491
inputmode="numeric"
9592
aria-describedby="date-error" aria-invalid="false" />
9693
</div>
9794
</div>
98-
<span id="date-error" class="error-message--margin-bottom-1 nhsuk-error-message" aria-live="polite" style="visibility: hidden;">
99-
</span>
10095
</div>
10196
</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>
13597
</div>

NHSUKViewComponents.Web/Views/Shared/Components/RadioList/Default.cshtml

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
<div class="nhsuk-form-group @(Model.HasError ? "nhsuk-form-group--error" : "")">
1111

12-
<fieldset class="nhsuk-fieldset" aria-describedby="@(!string.IsNullOrEmpty(Model.HintText) ? $"{Model.Label.RemoveWhitespace()}-hint" : string.Empty)">
12+
<fieldset id="@Model.AspFor" class="nhsuk-fieldset" aria-describedby="@(!string.IsNullOrEmpty(Model.HintText) ? $"{Model.Label.RemoveWhitespace()}-hint" : string.Empty)">
1313
<legend class="nhsuk-fieldset__legend nhsuk-fieldset__legend--m">
1414
@if (Model.IsPageHeading.GetValueOrDefault() == true)
1515
{
@@ -131,19 +131,4 @@
131131

132132
</div>
133133
</fieldset>
134-
<script>
135-
window.onload = function() {
136-
const id = "@Model.AspFor";
137-
const radioForm = document.querySelector("main form[novalidate='novalidate']");
138-
radioForm.addEventListener("submit", () => {
139-
const errorMessageParent = document.querySelector("div[data-valmsg-for='" + id + "']");
140-
const errorMessage = errorMessageParent.innerHTML;
141-
errorMessageParent.innerHTML = "";
142-
143-
setTimeout(function () {
144-
errorMessageParent.innerHTML = errorMessage;
145-
}, 0);
146-
});
147-
};
148-
</script>
149134
</div>

0 commit comments

Comments
 (0)