From c1bca491136b1de388c9346a870eb23b77ad4d8a Mon Sep 17 00:00:00 2001 From: James Wragg <5068769+jerotire@users.noreply.github.com> Date: Fri, 20 Sep 2024 15:16:39 +0100 Subject: [PATCH] fix: removes form__action field from failed postcode lookups (#341) * fix: removes form__action field from failed postcode lookups * chore: undo lint --- app/cdn/assets/_js/components/postcodeSearch.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/app/cdn/assets/_js/components/postcodeSearch.js b/app/cdn/assets/_js/components/postcodeSearch.js index 4de1e49761..e97e495df9 100644 --- a/app/cdn/assets/_js/components/postcodeSearch.js +++ b/app/cdn/assets/_js/components/postcodeSearch.js @@ -156,10 +156,10 @@ OLCS.postcodeSearch = (function(document, $, undefined) { if(response.hasErrors === false) { var rootElem = document.querySelector(root); var fieldsetSelector = 'fieldset[data-group="' + fieldset[0].getAttribute('data-group') + '"]'; - var fieldSetElement = rootElem.querySelector(fieldsetSelector); + var fieldSetElement = rootElem.querySelector(fieldsetSelector); var selectElement = fieldSetElement.querySelector('.address__select select'); if (null === selectElement) { - var nextInputElement = fieldSetElement.querySelector('input:not([type="hidden"]):not([id^="postcodeInput"])'); + var nextInputElement = fieldSetElement.querySelector('input:not([type="hidden"]):not([id^="postcodeInput"])'); nextInputElement.focus(); } else { selectElement.focus(); @@ -200,6 +200,13 @@ OLCS.postcodeSearch = (function(document, $, undefined) { function lookupError() { $(selectClass).hide(); $('.postcode-connectionLost').removeClass('govuk-visually-hidden'); + + // Remove form__action if defined; else submitting the form will result in another lookup and potential error. + $(container) + .closest('form') // Traverse up to the nearest parent form + .find('.form__action') // Find the form__action + .first() + .remove(); } // Ensure any time the page is re-rendered we resolve our components' state