Skip to content

Commit d0a4282

Browse files
committed
fix TiledCheckboxGroup so it can got value updated from outside like other Formzy controls
1 parent 3b3c713 commit d0a4282

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

components/Formsy/TiledCheckboxGroup.jsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,17 @@ class TiledCheckboxGroup extends Component {
1010
super(props)
1111
this.onChange = this.onChange.bind(this)
1212
this.getCheckMarkIconActive = this.getCheckMarkIconActive.bind(this)
13-
this.state = { curValue: props.getValue() || [] }
1413
}
1514

1615
onChange(value) {
17-
const index = this.state.curValue.indexOf(value)
18-
let newValue = [...this.state.curValue]
16+
const curValue = this.props.getValue() || []
17+
const index = curValue.indexOf(value)
18+
let newValue = [...curValue]
1919
if (index > -1) {
2020
newValue.splice(index, 1)
2121
} else {
2222
newValue.push(value)
2323
}
24-
this.setState({ curValue: newValue })
2524
this.props.setValue(newValue)
2625
this.props.onChange(this.props.name, newValue)
2726
}
@@ -35,12 +34,13 @@ class TiledCheckboxGroup extends Component {
3534

3635
render() {
3736
const { wrapperClass, options, theme, tabable } = this.props
37+
const curValue = this.props.getValue() || []
3838
const hasError = !this.props.isPristine() && !this.props.isValid()
3939
const disabled = this.props.isFormDisabled() || this.props.disabled
4040
const errorMessage = this.props.getErrorMessage() || this.props.validationError
4141

4242
const renderOption = (opt, idx) => {
43-
const checked = this.state.curValue.indexOf(opt.value) > -1
43+
const checked = curValue.indexOf(opt.value) > -1
4444
const itemClassnames = classNames('tiled-group-item', theme, {
4545
active: checked
4646
}, {

0 commit comments

Comments
 (0)