diff --git a/src/components/Select/FormsySelect.jsx b/src/components/Select/FormsySelect.jsx new file mode 100644 index 000000000..e87855570 --- /dev/null +++ b/src/components/Select/FormsySelect.jsx @@ -0,0 +1,33 @@ +import React from 'react' +import PropTypes from 'prop-types' +import { HOC as hoc } from 'formsy-react' + +import Select from './Select' + +/** + * This component is a formsy wrapper for the Select component + * @param {Object} props Component props + */ +const FormsySelect = props => { + // when setValueOnly is set to true, formsy should submit the 'option.value' instead of the whole 'option' object + const { onChange, setValueOnly, options } = props + const selectedOption = props.getValue() + + const onSelectionChange = selectedOption => { + props.setValue(setValueOnly ? selectedOption.value : selectedOption) + onChange && onChange(selectedOption) + } + const value = setValueOnly + ? _.find(options, o => o.value === selectedOption) + : selectedOption + + return