MCPcopy Create free account
hub / github.com/formkit/formkit / normalizeBoxes

Function normalizeBoxes

packages/inputs/src/features/normalizeBoxes.ts:13–42  ·  view source on GitHub ↗
(
  node: FormKitNode
)

Source from the content-addressed store, hash-verified

11 * @public
12 */
13export 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}

Callers 2

checkboxesFunction · 0.85
radiosFunction · 0.85

Calls 3

extendFunction · 0.90
slugifyFunction · 0.90
nextFunction · 0.85

Tested by

no test coverage detected