form.d.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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. /** Position of label */
  28. labelPosition: FormItemLabelPosition
  29. /** Width of label, and all form items will inherit from Form */
  30. labelWidth: string
  31. /** Suffix of the label */
  32. labelSuffix: string
  33. /** Whether to show the error message */
  34. showMessage: boolean
  35. /** Whether to display the error message inline with the form item */
  36. inlineMessage: boolean
  37. /** Whether to display an icon indicating the validation result */
  38. statusIcon: boolean
  39. /** Controls the size of components in this form */
  40. size: ElementUIComponentSize
  41. /**
  42. * Validate the whole form
  43. *
  44. * @param callback A callback to tell the validation result
  45. */
  46. validate (callback?: ValidateCallback): void
  47. /**
  48. * Validate a certain form item
  49. *
  50. * @param prop The property of `model` that is going to validate
  51. * @param callback A callback to tell the field validation result
  52. */
  53. validateField (prop: string, callback: ValidateFieldCallback): void
  54. /** reset all the fields and remove validation result */
  55. resetFields (): void
  56. }