Skip to content

Commit

Permalink
get value from href
Browse files Browse the repository at this point in the history
  • Loading branch information
bluedeepart committed Nov 27, 2024
1 parent 66655b2 commit 4c6c683
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 39 deletions.
27 changes: 13 additions & 14 deletions blocks/forms/formHelper.js
Original file line number Diff line number Diff line change
@@ -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':
Expand Down
29 changes: 4 additions & 25 deletions blocks/forms/forms.js
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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));
}

0 comments on commit 4c6c683

Please sign in to comment.