From 0d127144016de9c2ce23fcb3ccc9bd8b741f3164 Mon Sep 17 00:00:00 2001 From: Chris Hill-Scott Date: Tue, 23 Feb 2016 06:47:39 +0000 Subject: [PATCH] Automatically focus the first form field error MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Because we’re not showing a summary of error messages screen reader users might take a while to discover that there’s an error on the page. Since the only real action on a page with errors is to correct them this commit adds some Javascript to send focus straight to the first error message on a page. --- app/assets/javascripts/main.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/assets/javascripts/main.js b/app/assets/javascripts/main.js index f19cc9f9c..23cde7b51 100644 --- a/app/assets/javascripts/main.js +++ b/app/assets/javascripts/main.js @@ -1,3 +1,5 @@ $(() => GOVUK.modules.start()); $(() => new GOVUK.SelectionButtons('.block-label input, .sms-message-option input')); + +$(() => $('.error-message').eq(0).parent('label').next('input').trigger('focus'));