From fbef95a644437d17e94b067f20c7713f1b5f2f3d Mon Sep 17 00:00:00 2001 From: Matthias Kretschmann Date: Mon, 21 Sep 2020 18:18:24 +0000 Subject: [PATCH] fix empty optional fields --- .../molecules/FormFields/FilesInput/index.tsx | 8 ++------ src/models/FormPublish.ts | 11 ++++------- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/src/components/molecules/FormFields/FilesInput/index.tsx b/src/components/molecules/FormFields/FilesInput/index.tsx index cb0a7259a..9c07727ba 100644 --- a/src/components/molecules/FormFields/FilesInput/index.tsx +++ b/src/components/molecules/FormFields/FilesInput/index.tsx @@ -6,12 +6,8 @@ import FileInput from './Input' import { getFileInfo } from '../../../../utils' import { InputProps } from '../../../atoms/Input' -interface Values { - url: string -} - export default function FilesInput(props: InputProps): ReactElement { - const [field, meta, helpers] = useField(props) + const [field, meta, helpers] = useField(props.name) const [isLoading, setIsLoading] = useState(false) async function handleButtonClick(e: React.SyntheticEvent, url: string) { @@ -36,7 +32,7 @@ export default function FilesInput(props: InputProps): ReactElement { return ( <> - {field && typeof field.value === 'object' ? ( + {field?.value && field.value[0] && typeof field.value === 'object' ? ( ) : ( ({ termsAndConditions: Yup.boolean().required('Required'), // ---- optional fields ---- - copyrightHolder: Yup.string(), - tags: Yup.string(), + copyrightHolder: Yup.string().nullable(), + tags: Yup.string().nullable(), links: Yup.object().nullable() }) -export const initialValues: MetadataPublishForm = { +export const initialValues: Partial = { name: '', author: '', price: { @@ -50,8 +50,5 @@ export const initialValues: MetadataPublishForm = { description: '', license: '', access: '', - termsAndConditions: false, - copyrightHolder: '', - tags: '', - links: '' + termsAndConditions: false }