element-plus/packages/components/form/src/form-item.ts
JeremyWuuuuu adf1ecf3eb
fix(components): [el-form] validation with callbacks throws (#6669)
* fix(components): [el-form] validation with callbacks throws

- Fix Form component's validation with callbacks still throws error
- Fix FormItem component's validation with callbacks still throws error
- Update test cases to make sure this functionality's integrity

* Fix linter
2022-03-16 15:43:49 +08:00

54 lines
1.2 KiB
TypeScript

import { componentSizes } from '@element-plus/constants'
import { buildProps, definePropType } from '@element-plus/utils'
import type { ExtractPropTypes } from 'vue'
import type { Arrayable } from '@element-plus/utils'
import type { FormItemRule } from '@element-plus/tokens'
export const formItemValidateStates = [
'',
'error',
'validating',
'success',
] as const
export type FormItemValidateState = typeof formItemValidateStates[number]
export type FormItemProp = Arrayable<string>
export const formItemProps = buildProps({
label: String,
labelWidth: {
type: [String, Number],
default: '',
},
prop: {
type: definePropType<FormItemProp>([String, Array]),
},
required: {
type: Boolean,
default: undefined,
},
rules: {
type: definePropType<Arrayable<FormItemRule>>([Object, Array]),
},
error: String,
validateStatus: {
type: String,
values: formItemValidateStates,
},
for: String,
inlineMessage: {
type: [String, Boolean],
default: '',
},
showMessage: {
type: Boolean,
default: true,
},
size: {
type: String,
values: componentSizes,
},
} as const)
export type FormItemProps = ExtractPropTypes<typeof formItemProps>