diff --git a/CHANGELOG.md b/CHANGELOG.md index 1bd0929eb..3fb84329c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ - **Added:** Support for `labelClassName` in `uniforms-bootstrap3` and `uniforms-bootstrap4` themes. [\#548](https://github.com/vazco/uniforms/issues/548) - **Fixed:** Handling of `required` validation in `JSONSchemaBridge`. [\#554](https://github.com/vazco/uniforms/issues/554) +- **Fixed:** Weird behaviour of `SelectField` with `checkboxes` in `uniforms-antd`. [\#549](https://github.com/vazco/uniforms/issues/549) ## [v2.1.0](https://github.com/vazco/uniforms/tree/v2.1.0) (2019-06-18) diff --git a/packages/uniforms-antd/src/SelectField.js b/packages/uniforms-antd/src/SelectField.js index f37ac37d3..42801f531 100644 --- a/packages/uniforms-antd/src/SelectField.js +++ b/packages/uniforms-antd/src/SelectField.js @@ -8,39 +8,22 @@ import filterDOMProps from 'uniforms/filterDOMProps'; import wrapField from './wrapField'; const renderCheckboxes = props => - props.fieldType === Array ? ( - props.onChange(value)} - options={props.allowedValues.map(String)} - value={props.value.map(String).map(props.transform || String)} - {...filterDOMProps(props)} - /> - ) : ( - props.onChange(event.target.value)} - value={props.value} - {...filterDOMProps(props)} - > - {props.allowedValues.map(value => ( - - {props.transform ? props.transform(value) : value} - - ))} - - ); + React.createElement((props.fieldType === Array ? Checkbox : Radio).Group, { + disabled: props.disabled, + id: props.id, + name: props.name, + onChange: + props.fieldType === Array + ? value => props.onChange(value) + : event => props.onChange(event.target.value), + options: props.allowedValues.map(value => ({ + label: props.transform ? props.transform(value) : value, + value + })), + value: props.value, + ...filterDOMProps(props) + }); + const renderSelect = props => ( ( ))} ); + const Select = ({ checkboxes, ...props }) => wrapField(props, checkboxes ? renderCheckboxes(props) : renderSelect(props)); export default connectField(Select);