Skip to content

Commit

Permalink
Fixed SelectField with checkboxes in uniforms-antd (fixes #549).
Browse files Browse the repository at this point in the history
  • Loading branch information
radekmie committed Jul 12, 2019
1 parent 05026d3 commit 102c489
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 33 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
50 changes: 17 additions & 33 deletions packages/uniforms-antd/src/SelectField.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,39 +8,22 @@ import filterDOMProps from 'uniforms/filterDOMProps';
import wrapField from './wrapField';

const renderCheckboxes = props =>
props.fieldType === Array ? (
<Checkbox.Group
disabled={props.disabled}
id={props.id}
name={props.name}
onChange={value => props.onChange(value)}
options={props.allowedValues.map(String)}
value={props.value.map(String).map(props.transform || String)}
{...filterDOMProps(props)}
/>
) : (
<Radio.Group
disabled={props.disabled}
name={props.name}
onChange={event => props.onChange(event.target.value)}
value={props.value}
{...filterDOMProps(props)}
>
{props.allowedValues.map(value => (
<Radio
key={value}
value={value}
style={{
display: 'block',
height: '30px',
lineHeight: '30px'
}}
>
{props.transform ? props.transform(value) : value}
</Radio>
))}
</Radio.Group>
);
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 => (
<SelectAntD
allowClear={!props.required}
Expand All @@ -63,6 +46,7 @@ const renderSelect = props => (
))}
</SelectAntD>
);

const Select = ({ checkboxes, ...props }) =>
wrapField(props, checkboxes ? renderCheckboxes(props) : renderSelect(props));
export default connectField(Select);

0 comments on commit 102c489

Please sign in to comment.