form.d.ts 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. import { ElementUIComponent, ElementUIComponentSize } from './component'
  2. export type FormItemLabelPosition = 'left' | 'right' | 'top'
  3. export interface ValidateCallback {
  4. /**
  5. * The callback to tell the validation result
  6. *
  7. * @param isValid Whether the form is valid
  8. * @param invalidFields fields that fail validation
  9. */
  10. (isValid: boolean, invalidFields: object): void
  11. }
  12. export interface ValidateFieldCallback {
  13. /**
  14. * The callback to tell the field validation result
  15. *
  16. * @param errorMessage The error message. It will be empty if there is no error
  17. */
  18. (errorMessage: string): void
  19. }
  20. /** Form Component */
  21. export declare class ElForm extends ElementUIComponent {
  22. /** Data of form component */
  23. model: object
  24. /** Validation rules of form */
  25. rules: object
  26. /** Whether the form is inline */
  27. inline: boolean
  28. /** Whether the form is disabled */
  29. disabled: boolean
  30. /** Position of label */
  31. labelPosition: FormItemLabelPosition
  32. /** Width of label, and all form items will inherit from Form */
  33. labelWidth: string
  34. /** Suffix of the label */
  35. labelSuffix: string
  36. /** Whether to show the error message */
  37. showMessage: boolean
  38. /** Whether to display the error message inline with the form item */
  39. inlineMessage: boolean
  40. /** Whether to display an icon indicating the validation result */
  41. statusIcon: boolean
  42. /** Whether to trigger validation when the `rules` prop is changed */
  43. validateOnRuleChange: boolean
  44. /** Controls the size of components in this form */
  45. size: ElementUIComponentSize
  46. /**
  47. * Validate the whole form
  48. *
  49. * @param callback A callback to tell the validation result
  50. */
  51. validate (callback: ValidateCallback): void
  52. validate (): Promise<boolean>
  53. /**
  54. * Validate certain form items
  55. *
  56. * @param props The property of `model` or array of prop which is going to validate
  57. * @param callback A callback to tell the field validation result
  58. */
  59. validateField (props: string | string[], callback?: ValidateFieldCallback): void
  60. /** reset all the fields and remove validation result */
  61. resetFields (): void
  62. /** clear validation message for certain fields */
  63. clearValidate (props?: string | string[]): void
  64. }