@kong-ui-public/forms 4.11.17 → 4.11.18-pr.2066.325209e62.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -21,3 +21,51 @@ Here are the steps
21
21
 
22
22
  That's it - next time the version of @kong-ui-public/forms is used - your `src/forms/PostFunction.vue` will be presented when user selects `Post Function` plugin to install or edit.
23
23
 
24
+ ## how to add a custom field component
25
+ You can define custom field components to be used for specific fields.
26
+
27
+ For example, the field schema should like this:
28
+ ```json
29
+ {
30
+ type: 'array',
31
+ component: CatFoodField, // <== the custom Vue component
32
+ model: 'eats',
33
+ id: 'eats',
34
+ label: 'Eats',
35
+ }
36
+ ```
37
+
38
+ Please take a look at `sandbox/CatFoodField.vue` for an example of a custom field component.
39
+
40
+ You should have at least the following props, emits and function defined:
41
+ ```ts
42
+ const props = defineProps<{
43
+ disabled?: boolean
44
+ formOptions?: Record<string, any>
45
+ model?: Record<string, any>
46
+ schema: Record<string, any>
47
+ vfg: Record<string, any>
48
+ errors?: Array<any>
49
+ hint?: string
50
+ }>()
51
+
52
+ const emit = defineEmits<{
53
+ (event: 'modelUpdated', value: any, model: Record<string, any>): void
54
+ }>()
55
+
56
+ const { clearValidationErrors } = composables.useAbstractFields({
57
+ model: propsRefs.model,
58
+ schema: props.schema,
59
+ formOptions: props.formOptions,
60
+ emitModelUpdated: (data: { value: any, model: Record<string, any> }): void => {
61
+ emit('modelUpdated', data.value, data.model)
62
+ },
63
+ })
64
+
65
+ defineExpose({
66
+ clearValidationErrors,
67
+ })
68
+ ```
69
+
70
+ `composables.useAbstractFields` is a useful helper that can be used to simplify the implementation of custom field components.
71
+