Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Give CheckboxGroup its own custom event handler (fix #1998)
- Loading branch information
Showing
1 changed file
with
21 additions
and
3 deletions.
There are no files selected for viewing
24 changes: 21 additions & 3 deletions
24
packages/vulcan-ui-bootstrap/lib/components/forms/Checkboxgroup.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,26 @@ | ||
import React from 'react'; | ||
import { CheckboxGroup } from 'formsy-react-components'; | ||
import { Checkbox } from 'formsy-react-components'; | ||
import { registerComponent } from 'meteor/vulcan:core'; | ||
|
||
const CheckboxGroupComponent = ({refFunction, inputProperties}) => | ||
<CheckboxGroup {...inputProperties} ref={refFunction} />; | ||
// note: treat checkbox group the same as a nested component, using `path` | ||
const CheckboxGroupComponent = ({ refFunction, path, value, updateCurrentValues, inputProperties }) => | ||
inputProperties.options.map((option, i) => ( | ||
<Checkbox | ||
key={i} | ||
{...inputProperties} | ||
label={option.label} | ||
value={value.includes(option.value)} | ||
ref={refFunction} | ||
onChange={(name, isChecked) => { | ||
// give each individual checkbox its own path | ||
const checkboxPath = `${path}.${i}`; | ||
if (isChecked) { | ||
updateCurrentValues({ [checkboxPath]: option.value }); | ||
} else { | ||
updateCurrentValues({ [checkboxPath]: null }); | ||
} | ||
}} | ||
/> | ||
)); | ||
|
||
registerComponent('FormComponentCheckboxGroup', CheckboxGroupComponent); |