Skip to content

Commit

Permalink
fix: remove sampleRum calls, ensure submit is re-enabled when submiss…
Browse files Browse the repository at this point in the history
…ion finishes
  • Loading branch information
shsteimer committed Jun 25, 2024
1 parent ae5dc44 commit d9c59f5
Showing 1 changed file with 3 additions and 18 deletions.
21 changes: 3 additions & 18 deletions blocks/form/form.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import createField from './form-fields.js';
import { sampleRUM } from '../../scripts/aem.js';

async function createForm(formHref, submitHref) {
const { pathname } = new URL(formHref);
Expand Down Expand Up @@ -44,13 +43,6 @@ function generatePayload(form) {
return payload;
}

function handleSubmitError(form, error) {
// eslint-disable-next-line no-console
console.error(error);
form.querySelector('button[type="submit"]').disabled = false;
sampleRUM('form:error', { source: '.form', target: error.stack || error.message || 'unknown error' });
}

async function handleSubmit(form) {
if (form.getAttribute('data-submitting') === 'true') return;

Expand All @@ -69,7 +61,6 @@ async function handleSubmit(form) {
},
});
if (response.ok) {
sampleRUM('form:submit', { source: '.form', target: form.dataset.action });
if (form.dataset.confirmation) {
window.location.href = form.dataset.confirmation;
}
Expand All @@ -78,9 +69,11 @@ async function handleSubmit(form) {
throw new Error(error);
}
} catch (e) {
handleSubmitError(form, e);
// eslint-disable-next-line no-console
console.error(e);
} finally {
form.setAttribute('data-submitting', 'false');
submit.disabled = false;
}
}

Expand All @@ -106,12 +99,4 @@ export default async function decorate(block) {
}
}
});

window.addEventListener('pageshow', (event) => {
if (event.persisted) {
// re-enable form submission when back button is used
const submit = form.querySelector('button[type="submit"]');
if (submit) submit.disabled = false;
}
});
}

0 comments on commit d9c59f5

Please sign in to comment.