Skip to content

Commit

Permalink
Disable fields on load and empty on error
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Meijer committed Jun 19, 2023
1 parent 44c6f6c commit ad4ae6c
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions resources/views/tags/postcodeservice.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
return;
}
streetElement.disabled = true;
cityElement.disabled = true;
let xhr = new XMLHttpRequest();
let data = {
postcode: zipcode,
Expand All @@ -39,18 +42,25 @@
xhr.setRequestHeader('Content-Type', 'application/json;charset=UTF-8');
xhr.send(JSON.stringify(data));
xhr.onload = function () {
streetElement.disabled = false;
cityElement.disabled = false;
if (xhr.readyState !== xhr.DONE) {
streetElement.value = '';
cityElement.value = '';
return;
}
let responseData = JSON.parse(xhr.response);
if (!responseData?.city || !responseData?.street) {
streetElement.value = '';
cityElement.value = '';
return;
}
streetElement.value = responseData.street
cityElement.value = responseData.city
streetElement.value = responseData.street;
cityElement.value = responseData.city;
};
}
}
Expand Down

0 comments on commit ad4ae6c

Please sign in to comment.