generated from adobe/aem-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated the code alligned with forms code
- Loading branch information
1 parent
d6eaa73
commit d1fb0e9
Showing
1 changed file
with
20 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`, | ||
}); | ||
} |