Skip to content

Instantly share code, notes, and snippets.

View adroste's full-sized avatar

Alexander Droste adroste

View GitHub Profile
@adroste
adroste / dependentField.html
Created April 28, 2023 15:52
Salesforce Pardot Dependent Field on Checkbox
<script type="text/javascript">
function dependentCheckboxField(checkboxName, dependentFieldName) {
function normalizeString(str) {
return str.toLocaleLowerCase().replace(/\s/g, '').trim();
}
function findPardotFormFieldByLabel(label) {
for (const labelEl of document.querySelectorAll('#pardot-form label')) {
if (normalizeString(labelEl.innerHTML + '') === normalizeString(label))
return labelEl.parentElement;
}
@adroste
adroste / pathjoin.js
Created October 13, 2022 12:53
Properly joins paths, also works for URLs
export const pathJoin = (base, ...parts) => {
const trimSepRight = /\/+$/g;
const trimSepLeftRight = /^\/+|\/+$/g;
const partsTrimmed = parts.map(p => p.replace(trimSepLeftRight, ''));
return [base.replace(trimSepRight, '')].concat(partsTrimmed).join('/');
};