mirror of
https://github.com/vale981/Vulcan
synced 2025-03-10 12:36:39 -04:00
29 lines
977 B
JavaScript
29 lines
977 B
JavaScript
import React from 'react';
|
|
import { Checkbox } from 'formsy-react-components';
|
|
import { registerComponent } from 'meteor/vulcan:core';
|
|
|
|
// note: treat checkbox group the same as a nested component, using `path`
|
|
const CheckboxGroupComponent = ({ refFunction, path, value, updateCurrentValues, inputProperties }) => (
|
|
<div>
|
|
{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 });
|
|
}
|
|
}}
|
|
/>
|
|
))}
|
|
</div>
|
|
);
|
|
|
|
registerComponent('FormComponentCheckboxGroup', CheckboxGroupComponent);
|