Skip to content

Commit

Permalink
Updated the code alligned with forms code
Browse files Browse the repository at this point in the history
  • Loading branch information
teshukatepalli1 committed Oct 27, 2023
1 parent d6eaa73 commit d1fb0e9
Showing 1 changed file with 20 additions and 28 deletions.
48 changes: 20 additions & 28 deletions blocks/sidebar-form/sidebar-form.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,25 @@
function embedHubSpotForm(formFields) {
const script = document.createElement('script');
script.type = 'text/javascript';
script.src = '/scripts/v2.js';
script.charset = 'utf-8';
script.setAttribute('async', '');
script.onload = () => {
window.hbspt.forms.create(formFields);
};
document.head.appendChild(script);
}
import { readBlockConfig } from '../../scripts/aem.js';

export default function decorate(block) {
const formDetails = {};
const tableRows = block.querySelectorAll('tr');
tableRows.forEach((row) => {
const cells = row.children;
if (cells.length >= 2) {
const key = cells[0].innerText.trim();
const value = cells[1].innerText.trim();
formDetails[key] = key === 'target' ? `#${value}` : value;
}
});
// Add a delay of 4 seconds (4000 milliseconds) before loading the form
setTimeout(() => {
embedHubSpotForm(formDetails);
}, 3000);
let formConfig = {};

export default function decorate(block) {
formConfig = readBlockConfig(block);
const form = document.createElement('div');
form.id = formDetails.target.replace('#', '');
form.id = formConfig.target;
form.classList.add('content', 'outer');
block.textContent = '';
block.appendChild(form);
block.append(form);
}

export function isForm() {
return !!formConfig.target;
}

export function buildForm(hbspt) {
hbspt.forms.create({
region: formConfig.region,
portalId: formConfig.portalid,
formId: formConfig.formid,
target: `#${formConfig.target}`,
});
}

0 comments on commit d1fb0e9

Please sign in to comment.