Skip to content

Commit c1bca49

Browse files
authored
fix: removes form__action field from failed postcode lookups (#341)
* fix: removes form__action field from failed postcode lookups * chore: undo lint
1 parent 2bb78d9 commit c1bca49

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

app/cdn/assets/_js/components/postcodeSearch.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,10 @@ OLCS.postcodeSearch = (function(document, $, undefined) {
156156
if(response.hasErrors === false) {
157157
var rootElem = document.querySelector(root);
158158
var fieldsetSelector = 'fieldset[data-group="' + fieldset[0].getAttribute('data-group') + '"]';
159-
var fieldSetElement = rootElem.querySelector(fieldsetSelector);
159+
var fieldSetElement = rootElem.querySelector(fieldsetSelector);
160160
var selectElement = fieldSetElement.querySelector('.address__select select');
161161
if (null === selectElement) {
162-
var nextInputElement = fieldSetElement.querySelector('input:not([type="hidden"]):not([id^="postcodeInput"])');
162+
var nextInputElement = fieldSetElement.querySelector('input:not([type="hidden"]):not([id^="postcodeInput"])');
163163
nextInputElement.focus();
164164
} else {
165165
selectElement.focus();
@@ -200,6 +200,13 @@ OLCS.postcodeSearch = (function(document, $, undefined) {
200200
function lookupError() {
201201
$(selectClass).hide();
202202
$('.postcode-connectionLost').removeClass('govuk-visually-hidden');
203+
204+
// Remove form__action if defined; else submitting the form will result in another lookup and potential error.
205+
$(container)
206+
.closest('form') // Traverse up to the nearest parent form
207+
.find('.form__action') // Find the form__action
208+
.first()
209+
.remove();
203210
}
204211

205212
// Ensure any time the page is re-rendered we resolve our components' state

0 commit comments

Comments
 (0)