Form Relative
useFromContext
For each CForm
. It has a CFormContext
which can be fetched by useFormContext
const formContext: CFormContextProps = useFormContext()
interface CFormContextProps {
col?: number
labelWidth?: string
labelDirection?: 'row' | 'row-reverse' | 'column' | 'column-reverse'
labelAlign?: 'left' | 'right' | 'center'
addValidator?: (field: string, newValidator: Validator[]) => void
validateAll?: () => Promise<void> | void
clearAll?: () => void
validateField?: (field: string, value: any) => void | Promise<void>
clearField?: (field: string) => void
errors?: Errors
}
interface Validators {
[key: string]: Validator[]
}
interface Errors {
[key: string]: string | false
}
type Validator = (value: any) => string | false | Promise<string | false>
For More see CFormItem.tsx Source Code
useFormItemContext
For each CFormItem
. It has a CFormItemContext
which can be fetched by useFormItemContext
const formItemContext: CFormItemContextProps = useFormItemContext()
interface CFormItemContextProps {
clearCurrent?: () => void
validateCurrent?: (v: any) => void
hasError?: false | string
}
For more usage see CInput.tsx Source Code