Skip to content

Commit

Permalink
rsvp fields mandated fields are authorable now
Browse files Browse the repository at this point in the history
  • Loading branch information
qiyundai committed Aug 19, 2024
1 parent 05c2511 commit 8cbcff0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
export function onSubmit(component, props) {
if (component.closest('.fragment')?.classList.contains('hidden')) return;

const defaultFields = ['firstName', 'lastName', 'email', 'jobTitle'];
const defaultFields = component.dataset.mandatedfields?.split(',');

const rsvpFormFields = {
visible: [...defaultFields, ...Array.from(component.querySelectorAll('sp-checkbox.check-appear[checked]')).map((f) => f.name)],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ function convertString(input) {
return result;
}

async function decorateRSVPFields(row) {
async function decorateRSVPFields(el) {
const row = el.querySelector(':scope > div:last-of-type');

if (!row) return;

row.classList.add('rsvp-checkboxes');
const configSheetLocation = row.querySelector('a')?.href;
const config = await fetch(configSheetLocation)
Expand All @@ -30,6 +34,8 @@ async function decorateRSVPFields(row) {
row.innerHTML = '';
row.append(fieldConfigTable);

el.dataset.mandatedfields = config.data.filter((f) => f.Required === 'x').map((f) => f.Field);

config.data.filter((f) => f.Required !== 'x' && f.Type !== 'submit').forEach((field) => {
const fieldRow = createTag('tr', { class: 'field-row' }, '', { parent: tbody });
const tds = [];
Expand All @@ -46,5 +52,5 @@ async function decorateRSVPFields(row) {
export default async function init(el) {
el.classList.add('form-component');
generateToolTip(el.querySelector(':scope > div:first-of-type'));
await decorateRSVPFields(el.querySelector(':scope > div:last-of-type'));
await decorateRSVPFields(el);
}

0 comments on commit 8cbcff0

Please sign in to comment.