Skip to content

Commit a44d2a2

Browse files
committed
feat: add demo label plugin for FormKit nodes with help text support by title and hide help section
1 parent 014e4ea commit a44d2a2

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed

src/plugins/index.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,39 @@ export function addPrimeAsteriskPlugin(node: FormKitNode): void {
2424
}
2525
})
2626
}
27+
28+
export function addLabelPlugin(node: FormKitNode): void {
29+
if (!node.props.type.startsWith('prime'))
30+
return
31+
32+
node.on('created', () => {
33+
if (node.props.definition?.schema) {
34+
const schemaFn = node.props.definition?.schema as FormKitExtendableSchemaRoot
35+
node.props.definition!.schema = (sectionsSchema = {}) => {
36+
sectionsSchema.label = {
37+
children: [{
38+
$el: 'span',
39+
attrs: {
40+
title: '$help',
41+
class: 'p-formkit-label',
42+
},
43+
children: ['$label'],
44+
}, {
45+
$el: 'span',
46+
if: '$state.required',
47+
attrs: {
48+
class: 'p-formkit-required',
49+
title: '$help',
50+
},
51+
children: ['*'],
52+
}],
53+
}
54+
sectionsSchema.help = {
55+
children: [],
56+
}
57+
58+
return schemaFn(sectionsSchema)
59+
}
60+
}
61+
})
62+
}

0 commit comments

Comments
 (0)