Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sitecore-jss-forms] File upload validation error #1213

Merged
merged 1 commit into from
Oct 20, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions packages/sitecore-jss-forms/src/serializeForm.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {
FormField,
ValueFormField,
instanceOfButtonFormField,
instanceOfFormFieldSection,
instanceOfValueFormField,
} from './FormField';
import { TrackableValueFormField } from './FormTracker';
import { getFieldValueFromModel } from './getFieldValueFromModel';
import { HtmlFormField } from './HtmlFormField';
import { JssFormData } from './JssFormData';
Expand Down Expand Up @@ -47,11 +47,7 @@ export function serializeForm(form: SitecoreForm, options?: SerializeFormOptions
* @param {Array<FormField>} fields
* @param {SerializeFormOptions} options
*/
function pushFields(
result: JssFormData,
fields: ((TrackableValueFormField & FormField<FileInputViewModel>) | FormField)[],
options: SerializeFormOptions
) {
function pushFields(result: JssFormData, fields: FormField[], options: SerializeFormOptions) {
fields.forEach((field) => {
if (
instanceOfButtonFormField(field) &&
Expand All @@ -61,16 +57,15 @@ function pushFields(
pushField(result, field.navigationButtonsField);
pushField(result, field.navigationStepField);
} else if (instanceOfValueFormField(field)) {
pushField(result, field.indexField);
pushField(result, field.fieldIdField);
if (field.valueField.name.endsWith('.Files')) {
const fileUploadField: TrackableValueFormField & FormField<FileInputViewModel> = field;

if (!fileUploadField.originalValue && !fileUploadField.model.files) {
const fileUploadField = field as ValueFormField<FileInputViewModel>;
if (!fileUploadField.model.files) {
return;
}
}

pushField(result, field.indexField);
pushField(result, field.fieldIdField);
// get stored value (i.e. if a multistep form)
if (instanceOfInputViewModel(field.model) && options.fieldValueParser) {
const fieldValue = options.fieldValueParser(field);
Expand Down