diff --git a/blocks/forms/formHelper.js b/blocks/forms/formHelper.js index 7eb86cbc6..7601b2c27 100644 --- a/blocks/forms/formHelper.js +++ b/blocks/forms/formHelper.js @@ -1,22 +1,21 @@ import { input } from '../../scripts/dom-helpers.js'; +import { toCamelCase } from '../../scripts/lib-franklin.js'; import { getCookie } from '../../scripts/scripts.js'; -/* Helper functions */ -export const RESOURCEKEYS = ['heading', 'region', 'portalId', 'formId', 'redirectUrl', 'productFamily', 'productPrimaryApplication', 'cmp', 'jobTitle', 'website', 'productImage']; - -export function getDefaultForKey(key) { - switch (key) { - case 'heading': - return ''; - case 'region': - return 'na1'; - case 'portalId': - return '20222769 '; - default: - return ''; - } +// extract data from table +export async function extractFormData(block) { + const blockData = {}; + [...block.children].forEach((row) => { + const key = toCamelCase(row.children[0].textContent.trim().toLowerCase()); + const valueContainer = row.children[1]; + const link = valueContainer.querySelector('a'); + const value = link ? link.href : valueContainer.textContent.trim(); + blockData[key] = value; + }); + return blockData; } +// get form id export function getFormId(type) { switch (type) { case 'app-note': diff --git a/blocks/forms/forms.js b/blocks/forms/forms.js index 68ef68065..396f8ac12 100644 --- a/blocks/forms/forms.js +++ b/blocks/forms/forms.js @@ -1,34 +1,12 @@ import { a, button, div, h3, label, } from '../../scripts/dom-helpers.js'; -import { loadCSS, toCamelCase, toClassName } from '../../scripts/lib-franklin.js'; +import { loadCSS, toClassName } from '../../scripts/lib-franklin.js'; import { loadScript } from '../../scripts/scripts.js'; import { - createSalesforceForm, - getDefaultForKey, - getFormFieldValues, - getFormId, - RESOURCEKEYS, - updateFormFields, + createSalesforceForm, extractFormData, getFormFieldValues, getFormId, updateFormFields, } from './formHelper.js'; -/* extract data from table */ -async function extractFormData(block) { - const blockData = {}; - [...block.children].forEach((row) => { - const key = toCamelCase(row.children[0].textContent.trim().toLowerCase()); - const value = row.children[1].textContent.trim(); - blockData[key] = value; - }); - - RESOURCEKEYS.forEach((key) => { - if (!blockData[key]) { - blockData[key] = getDefaultForKey(key); - } - }); - return blockData; -} - /* create hubspot form */ export function createHubSpotForm(formConfig, target, type = '') { try { @@ -104,6 +82,7 @@ export default async function decorate(block, index) { }), ); - block.replaceWith(form); + block.innerHTML = ''; + block.appendChild(form); loadHubSpotScript(createHubSpotForm.bind(null, formConfig, target, pageType)); }