BartelsCreativeCo Posted January 4 Posted January 4 Hello, I'm looking for a solution to make the Newsletter Block sign-up form more accessible to meet ADA compliance. I keep getting flagged when I run it through an accessibility scanner. I've attached a screenshot from the audit for context. Right now the default newsletter blocks don't allow for official form field labelling, but rather show the form field description as placeholder text. Unfortunately, placeholder text isn't read by screen readers and therefore doesn't meet accessibility compliance. I'm looking for a javascript solution that would allow me to add currently non-existent "aria-labels" to those form fields. I have found some options for this but they require the HTML to have the aria-label attributes in place—which this newsletter block does not. Does anyone have a solution?
jpeter Posted January 5 Posted January 5 @BartelsCreativeCo The following JS should do the trick: JavaScript (function(){ setTimeout(() => { document.querySelector('[name="fname"]').setAttribute('aria-label', 'First Name'); document.querySelector('[name="lname"]').setAttribute('aria-label', 'Last Name'); document.querySelector('[name="email"]').setAttribute('aria-label', 'Email Address'); }, 500); })() Make sure you add it in the Footer section and in between <script> tags like so: <script> // Add JS here </script> Full stack developer who loves helping people out with anything web related. If you'd like to support me, buy me a coffee!
BartelsCreativeCo Posted January 5 Author Posted January 5 1 hour ago, jpeter said: @BartelsCreativeCo The following JS should do the trick: JavaScript (function(){ setTimeout(() => { document.querySelector('[name="fname"]').setAttribute('aria-label', 'First Name'); document.querySelector('[name="lname"]').setAttribute('aria-label', 'Last Name'); document.querySelector('[name="email"]').setAttribute('aria-label', 'Email Address'); }, 500); })() Make sure you add it in the Footer section and in between <script> tags like so: <script> // Add JS here </script> @jpeter that worked great for adding the labels, thank you! I apparently still need to add an "Aria-required" designation though. Would you be able to show me how that factors into the code?
Solution jpeter Posted January 5 Solution Posted January 5 @BartelsCreativeCo Here's updated code to also include the aria-required attribute to each of of the input fields: (function(){ setTimeout(() => { document.querySelector('[name="fname"]').setAttribute('aria-label', 'First Name'); document.querySelector('[name="fname"]').setAttribute('aria-required', 'true'); document.querySelector('[name="lname"]').setAttribute('aria-label', 'Last Name'); document.querySelector('[name="lname"]').setAttribute('aria-required', 'true'); document.querySelector('[name="email"]').setAttribute('aria-label', 'Email Address'); document.querySelector('[name="email"]').setAttribute('aria-required', 'true'); }, 500); })() LouLouHarvey 1 Full stack developer who loves helping people out with anything web related. If you'd like to support me, buy me a coffee!
cpalmateer7582 Posted February 20 Posted February 20 Hi, I have the same problem and put the code into the footer as suggested and it still gives me errors on AccessScan. I was wondering if there is a delay or an issue with the code itself. <script> // Aria-labels for newsletter (function(){ setTimeout(() => { document.querySelector('[name="fname"]').setAttribute('aria-label', 'First Name'); document.querySelector('[name="fname"]').setAttribute('aria-required', 'true'); document.querySelector('[name="lname"]').setAttribute('aria-label', 'Last Name'); document.querySelector('[name="lname"]').setAttribute('aria-required', 'true'); document.querySelector('[name="email"]').setAttribute('aria-label', 'Email Address'); document.querySelector('[name="email"]').setAttribute('aria-required', 'true'); }, 500); })() </script>
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment