diff --git a/src/components/record/JSONRecordForm.tsx b/src/components/record/JSONRecordForm.tsx index 05874ac57..0db78141f 100644 --- a/src/components/record/JSONRecordForm.tsx +++ b/src/components/record/JSONRecordForm.tsx @@ -2,6 +2,7 @@ import React from "react"; import BaseForm from "../BaseForm"; import JSONEditor from "../JSONEditor"; import { RJSFSchema, UiSchema } from "@rjsf/utils"; +import { omit } from "../../utils"; const schema: RJSFSchema = { type: "string", @@ -51,11 +52,9 @@ type Props = { }; function splitAttachment(record: string) { - const jsRecord = JSON.parse(record); + let jsRecord = JSON.parse(record); const attachment = jsRecord.attachment || {}; - if (jsRecord.attachment) { - delete jsRecord.attachment; - } + jsRecord = omit(jsRecord, ["attachment"]); return { attachment: attachment, jsonContent: JSON.stringify(jsRecord), diff --git a/src/components/record/RecordForm.tsx b/src/components/record/RecordForm.tsx index 247f0593f..b7a0adabb 100644 --- a/src/components/record/RecordForm.tsx +++ b/src/components/record/RecordForm.tsx @@ -171,7 +171,7 @@ export default function RecordForm(props: Props) { record={JSON.stringify(recordData, null, 2)} onSubmit={handleOnSubmit} attachmentEnabled={attachment?.enabled} - // require an attachment on initial insert if attachments are required + // require an attachment on insert if attachments are required, don't need to re-upload on every edit attachmentRequired={attachment?.required && !record} > {buttons}