form.d.ts 2.0 KB

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