Skip to content

Commit 111fd1e

Browse files
committed
refactor: add composable for common input functions
1 parent 71aae45 commit 111fd1e

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/composables/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1+
import { useFormKitInput } from './useFormKitInput'
12
import { useFormKitSchema } from './useFormKitSchema'
23
import { useInputEditorSchema } from './useInputEditorSchema'
34

45
export {
6+
useFormKitInput,
57
useFormKitSchema,
68
useInputEditorSchema,
79
}

src/composables/useFormKitInput.ts

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import { computed } from 'vue'
2+
3+
export function useFormKitInput(context: any) {
4+
const styleClass = computed(() => {
5+
return (context?.state.validationVisible && !context?.state.valid) ? `${context?.attrs?.class} p-invalid` : context?.attrs?.class
6+
})
7+
8+
const wrapperClass = computed(() => {
9+
return context?.wrapperClass ? `p-formkit ${context?.wrapperClass}` : 'p-formkit '
10+
})
11+
12+
function handleBlur(event: Event) {
13+
context?.handlers.blur(event)
14+
}
15+
16+
function handleChange(_: any) {
17+
context?.node.input(context?._value)
18+
}
19+
20+
function handleInput(_: any) {
21+
context?.node.input(context?._value)
22+
}
23+
24+
function handleSelect(e: any) {
25+
context?.node.input(e)
26+
}
27+
28+
return { styleClass, wrapperClass, handleBlur, handleChange, handleInput, handleSelect }
29+
}

0 commit comments

Comments
 (0)