Skip to content

Commit

Permalink
Updates build form types and simplifies logic a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
thiessenp-cds committed Aug 15, 2024
1 parent 880d9c1 commit 697e888
Showing 1 changed file with 6 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,13 @@ export function buildFormDataObject(formRecord: PublicFormRecord, values: Respon

function _handleDynamicRowTypeIfNeeded(
element: FormElement,
value: Response
value: Response | Responses[]
): [string, string | FileInputResponse][] {
if (element.type === FormElementTypes.dynamicRow) {
if (element.type === FormElementTypes.dynamicRow && Array.isArray(value)) {
if (element.properties.subElements === undefined) return [];

const responses = value as Responses[];
const subElements = element.properties.subElements;

// Handle Pages (Groups) which can be empty (response value of "") depending on the path a user
// chose. Also check subElements just for safety.
if (!Array.isArray(responses) || !Array.isArray(subElements)) {
return [];
}

/**
* We are creating a new data structure (to be passed to the submit API) from the multiple responses that could have been entered
* for the dynamic row component we are currently processing. */
Expand All @@ -72,15 +65,15 @@ function _handleDynamicRowTypeIfNeeded(
// `flat` function is needed because we use a `map` in a `map`.
.flat()
);
} else {
const result = _handleFormDataType(element, value);
return result ? [result] : [];
}

const result = _handleFormDataType(element, value);
return result ? [result] : [];
}

function _handleFormDataType(
element: FormElement,
value: Response
value: Response | Responses[]
): [string, string | FileInputResponse] | undefined {
switch (element.type) {
case FormElementTypes.textField:
Expand Down

0 comments on commit 697e888

Please sign in to comment.