Skip to content

Commit

Permalink
fix: removes form__action field from failed postcode lookups (#341)
Browse files Browse the repository at this point in the history
* fix: removes form__action field from failed postcode lookups

* chore: undo lint
  • Loading branch information
jerotire committed Sep 20, 2024
1 parent 2bb78d9 commit c1bca49
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions app/cdn/assets/_js/components/postcodeSearch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit c1bca49

Please sign in to comment.