diff --git a/site/content/docs/5.3/examples/form/form.js b/site/content/docs/5.3/examples/form/form.js index 77c03e4563..1e1e864999 100644 --- a/site/content/docs/5.3/examples/form/form.js +++ b/site/content/docs/5.3/examples/form/form.js @@ -17,6 +17,19 @@ const invalidItems = form.querySelectorAll(':invalid') invalidItems[0].focus() invalidItems[0].setAttribute('data-focus-visible-added', '') + // Add the id of the corresponding invalid message to each invalid field + invalidItems.forEach(element => { + const closestLabel = element.parentElement.querySelector('.form-label').getAttribute('id') + const closestInvalidFeedback = element.parentElement.querySelector('.invalid-feedback').getAttribute('id') + const valuesArray = [closestLabel, closestInvalidFeedback].join(' ') + element.setAttribute('aria-labelledby', valuesArray) + }) + // Remove the id of the corresponding invalid message to each valid field + const validItems = form.querySelectorAll(':valid:not([type="submit"])') + validItems.forEach(element => { + const closestLabel = element.parentElement.querySelector('.form-label').getAttribute('id') + element.setAttribute('aria-labelledby', closestLabel) + }) } form.classList.add('was-validated') diff --git a/site/content/docs/5.3/examples/form/index.html b/site/content/docs/5.3/examples/form/index.html index 990f557f4a..ad7fb120b0 100644 --- a/site/content/docs/5.3/examples/form/index.html +++ b/site/content/docs/5.3/examples/form/index.html @@ -128,7 +128,7 @@