Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
name="@Model.DayId"
value="@Model.DayValue"
type="text"
pattern="[0-9]*"
min="1"
max="31"
step="1"
Expand All @@ -71,7 +70,6 @@
name="@Model.MonthId"
value="@Model.MonthValue"
type="text"
pattern="[0-9]*"
min="1"
max="12"
step="1"
Expand All @@ -87,7 +85,6 @@
name="@Model.YearId"
value="@Model.YearValue"
type="text"
pattern="[0-9]*"
min="1900"
max="9999"
step="1"
Expand All @@ -99,37 +96,4 @@
</span>
</div>
</fieldset>
<script>
const fields = [@Model.DayId, @Model.MonthId, @Model.YearId];

const errorElement = document.getElementById('date-error');
for (let field of fields) {
const inputElement = document.getElementById(field.id);

inputElement.addEventListener('input', function (event) {

if (event.inputType === 'deleteContentBackward') {
return;
}

const value = event.data;
const min = parseInt(inputElement.getAttribute('min'));
const max = parseInt(inputElement.getAttribute('max'));

inputElement.setAttribute('aria-invalid', 'false');
errorElement.textContent = '';
errorElement.style.visibility = 'hidden';

setTimeout(function () {
if (value < 0 || value > max || !value.match(/^[0-9]*$/)) {
inputElement.value = inputElement.value.slice(0, -1) + 1;
inputElement.value = inputElement.value.slice(0, -1);
inputElement.setAttribute('aria-invalid', 'true');
errorElement.textContent = `Invalid input. Please enter a number between ${min} and ${max}.`;
errorElement.style.visibility = 'visible';
}
}, 0);
});
}
</script>
</div>
</div>
Loading