Skip to content
Snippets Groups Projects
Commit 020e9953 authored by Yannis Barlas's avatar Yannis Barlas
Browse files

fix(ui): handle empty value in form builder select

parent ddd950d0
No related branches found
No related tags found
No related merge requests found
import React, { useState } from 'react' import React, { useState } from 'react'
import PropTypes from 'prop-types' import PropTypes from 'prop-types'
import { map, omitBy } from 'lodash' import { isEmpty, map, omitBy } from 'lodash'
import { ValidatedFieldFormik, Menu, Button } from '@pubsweet/ui'
import { Formik } from 'formik' import { Formik } from 'formik'
import { ValidatedFieldFormik, Menu, Button } from '@pubsweet/ui'
import FormProperties from './FormProperties' import FormProperties from './FormProperties'
import components from './config/Elements' import components from './config/Elements'
import * as elements from './builderComponents' import * as elements from './builderComponents'
...@@ -50,9 +52,14 @@ const ComponentProperties = ({ ...@@ -50,9 +52,14 @@ const ComponentProperties = ({
component={elements[value.component].default} component={elements[value.component].default}
key={`${selectedComponent}-${key}`} key={`${selectedComponent}-${key}`}
name={key} name={key}
onChange={val => onChange={val => {
if (isEmpty(val)) {
setFieldValue(key, null)
return
}
setFieldValue(key, val.target ? val.target.value : val) setFieldValue(key, val.target ? val.target.value : val)
} }}
{...value.props} {...value.props}
/> />
</Section> </Section>
......
...@@ -24,6 +24,7 @@ const ValidationMenu = input => ( ...@@ -24,6 +24,7 @@ const ValidationMenu = input => (
</Section> </Section>
) )
} }
return null return null
})} })}
</> </>
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment