From 43ba2778f0ace12dd1192fc2e6d3e5589f11b9fa Mon Sep 17 00:00:00 2001 From: Davide Dippolito Date: Wed, 5 Jun 2024 10:53:57 +0100 Subject: [PATCH] Forces controller initialization on every personal details form --- .../javascript/js_components/mobileFocus/mobileFocus.js | 8 ++++---- .../jobseekers/profiles/personal_details/name.html.slim | 2 +- .../profiles/personal_details/phone_number.html.slim | 2 +- .../jobseekers/profiles/personal_details/work.html.slim | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/app/assets/javascript/js_components/mobileFocus/mobileFocus.js b/app/assets/javascript/js_components/mobileFocus/mobileFocus.js index ac6fdaada7..2511686995 100644 --- a/app/assets/javascript/js_components/mobileFocus/mobileFocus.js +++ b/app/assets/javascript/js_components/mobileFocus/mobileFocus.js @@ -1,21 +1,21 @@ import { Controller } from '@hotwired/stimulus'; -export default class extends Controller { +export default class MobileFocusController extends Controller { connect() { this.handleMobilePageFocus(); } static detectMobile() { - return /iPhone|iPad|iPod|Android/i.test(navigator.userAgent); + return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent); } handleMobilePageFocus() { - if (!this.detectMobile()) { + if (!this.constructor.detectMobile()) { return; } if (window.location.href.includes('profile/personal-details')) { - const skipLinkElement = document.getElementsByClassName('govuk-skip-link'); + const skipLinkElement = document.querySelector('.govuk-skip-link'); if (skipLinkElement && skipLinkElement.length > 0) { skipLinkElement[0].focus(); diff --git a/app/views/jobseekers/profiles/personal_details/name.html.slim b/app/views/jobseekers/profiles/personal_details/name.html.slim index 299cb6b361..fbc49ee37b 100644 --- a/app/views/jobseekers/profiles/personal_details/name.html.slim +++ b/app/views/jobseekers/profiles/personal_details/name.html.slim @@ -5,7 +5,7 @@ .govuk-grid-row .govuk-grid-column-two-thirds - = form_for @step, url: { action: :update }, method: :post, as: :personal_details_form do |f| + = form_for @step, url: { action: :update }, method: :post, as: :personal_details_form, html: { data: { controller: "mobile-focus" } } do |f| = f.govuk_error_summary = f.govuk_fieldset legend: { text: t(".heading"), tag: "h1", size: "l" }, caption: { text: t(".caption"), size: "l" } do diff --git a/app/views/jobseekers/profiles/personal_details/phone_number.html.slim b/app/views/jobseekers/profiles/personal_details/phone_number.html.slim index e0efb9056e..9873abfa0b 100644 --- a/app/views/jobseekers/profiles/personal_details/phone_number.html.slim +++ b/app/views/jobseekers/profiles/personal_details/phone_number.html.slim @@ -5,7 +5,7 @@ .govuk-grid-row .govuk-grid-column-two-thirds - = form_for @step, url: { action: :update }, method: :post, as: :personal_details_form do |f| + = form_for @step, url: { action: :update }, method: :post, as: :personal_details_form, html: { data: { controller: "mobile-focus" } } do |f| = f.govuk_error_summary = f.govuk_radio_buttons_fieldset :phone_number_provided, legend: { text: t(".heading"), tag: "h1", size: "l" }, caption: { text: t(".caption"), size: "l" } do diff --git a/app/views/jobseekers/profiles/personal_details/work.html.slim b/app/views/jobseekers/profiles/personal_details/work.html.slim index 139e40c761..4fc18b93e8 100644 --- a/app/views/jobseekers/profiles/personal_details/work.html.slim +++ b/app/views/jobseekers/profiles/personal_details/work.html.slim @@ -5,7 +5,7 @@ .govuk-grid-row .govuk-grid-column-two-thirds - = form_for @step, url: { action: :update }, method: :post, as: :personal_details_form do |f| + = form_for @step, url: { action: :update }, method: :post, as: :personal_details_form, html: { data: { controller: "mobile-focus" } } do |f| = f.govuk_error_summary = f.govuk_radio_buttons_fieldset :right_to_work_in_uk,