( node: FormKitNode )
| 11 | * @public |
| 12 | */ |
| 13 | export default function normalizeBoxes( |
| 14 | node: FormKitNode |
| 15 | ): FormKitMiddleware<{ prop: string | symbol; value: any }> { |
| 16 | return function (prop, next) { |
| 17 | if (prop.prop === 'options' && Array.isArray(prop.value)) { |
| 18 | prop.value = prop.value.map((option) => { |
| 19 | if (!option.attrs?.id) { |
| 20 | return extend(option, { |
| 21 | attrs: { |
| 22 | id: `${node.props.id}-option-${slugify(String(option.value))}`, |
| 23 | }, |
| 24 | }) |
| 25 | } |
| 26 | return option |
| 27 | }) |
| 28 | if (node.props.type === 'checkbox' && !Array.isArray(node.value)) { |
| 29 | if (node.isCreated) { |
| 30 | node.input([], false) |
| 31 | } else { |
| 32 | node.on('created', () => { |
| 33 | if (!Array.isArray(node.value)) { |
| 34 | node.input([], false) |
| 35 | } |
| 36 | }) |
| 37 | } |
| 38 | } |
| 39 | } |
| 40 | return next(prop) |
| 41 | } |
| 42 | } |
no test coverage detected