Skip to content

Commit 96fab28

Browse files
committed
Form logic working (pending UI)
1 parent 91c9f98 commit 96fab28

File tree

2 files changed

+74
-8
lines changed

2 files changed

+74
-8
lines changed

eds/blocks/form/form.css

+23-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,29 @@
11
.form.block {
22
color: var(--calcite-ui-text-1);
3+
background-color: var(--calcite-ui-foreground-1);
34

4-
& > div:first-child {
5+
&.card-modal {
6+
& > div.one-form {
7+
display: none;
8+
}
9+
10+
&.modal-active > div.one-form {
11+
display: block;
12+
}
13+
14+
.card-modal-content {
15+
p {
16+
color: white;
17+
background-color: black;
18+
}
19+
20+
img {
21+
filter: brightness(0) saturate(100%) invert(67%) sepia(69%) saturate(375%) hue-rotate(121deg) brightness(103%) contrast(86%);
22+
}
23+
}
24+
}
25+
26+
& > div.one-form {
527
inline-size: 1440px;
628
max-inline-size: 96vw;
729
margin: auto;

eds/blocks/form/form.js

+51-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { div } from '../../scripts/dom-helpers.js';
1+
import { div, a } from '../../scripts/dom-helpers.js';
22
import {
33
loadScript,
44
loadCSS,
@@ -10,10 +10,33 @@ export default async function decorate(block) {
1010
block.closest('.section').classList.add('calcite-mode-dark', 'dark');
1111
block.classList.add('calcite-mode-dark', 'dark');
1212
const config = readBlockConfig(block);
13-
const divId = getMetadata('formdivid') || config.divId;
14-
config.divId = divId;
13+
const divId = getMetadata('formdivid') || config.divid;
14+
config.divid = divId;
1515

16-
block.replaceChildren(div({ id: divId }));
16+
const formDiv = div({
17+
id: divId,
18+
class: 'one-form',
19+
});
20+
if (block.classList.contains('card-modal')) {
21+
delete config.cardcontent;
22+
// we need to find it "again" because the html is not preserved in readBlockConfig
23+
const cardContent = [...block.querySelectorAll(':scope > div')]
24+
.find((el) => el.firstElementChild.textContent === 'cardContent')
25+
.lastElementChild;
26+
const cardModalContent = a({ class: 'card-modal-content' }, cardContent);
27+
cardModalContent.addEventListener('click', () => {
28+
block.classList.add('modal-active');
29+
window.openOneFormModal();
30+
});
31+
block.replaceChildren(
32+
formDiv,
33+
cardModalContent,
34+
);
35+
} else {
36+
block.replaceChildren(formDiv);
37+
}
38+
39+
// TODO get card if modals
1740

1841
await Promise.all([
1942
loadCSS('https://webapps-cdn.esri.com/CDN/one-form/one-form.css'),
@@ -23,11 +46,10 @@ export default async function decorate(block) {
2346
config.aemEditMode = false;
2447

2548
const baseFormProps = {
26-
divId,
2749
aemFieldServiceBasePath: 'https://assets.esri.com/content/experience-fragments/esri-sites/en-us/site-settings/one-form-admin/master',
2850
aemEditMode: 'false',
2951
mode: 'basic-progressive-form',
30-
formOpensInAModal: '',
52+
formOpensInAModal: 'true',
3153
modalTitle: '',
3254
leftAligned: '',
3355
darkMode: true, // metadata.mode === 'dark',
@@ -68,5 +90,27 @@ export default async function decorate(block) {
6890
// merge config and baseFormProps
6991
const formProps = { ...baseFormProps, ...config };
7092

71-
window.initOneForm(divId, formProps);
93+
console.log('formProps', formProps);
94+
95+
// const form = window.oneForm.attachToForm(divId);
96+
// form.on('load', (formApi) => {
97+
// //Perform API actions here
98+
// console.log('form loaded');
99+
// });
100+
101+
// workaround for initOneForm requiring the form div to be in the DOM,
102+
// which it is not when loaded as a fragment
103+
const observer = new MutationObserver((mutationsList) => {
104+
mutationsList.forEach((mutation) => {
105+
if (mutation.type === 'childlist') {
106+
console.log('A child node has been added or removed.', document.getElementById(divId));
107+
}
108+
if (mutation.type === 'childList' && document.getElementById(divId)) {
109+
const initResult = window.initOneForm(divId, formProps);
110+
console.log('init result', initResult);
111+
observer.disconnect();
112+
}
113+
});
114+
});
115+
observer.observe(document.body, { childList: true, subtree: true });
72116
}

0 commit comments

Comments
 (0)