get-node-form.mdx 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. # getNodeForm
  2. 获取节点的表单能力,需要开启 节点引擎才能使用
  3. [> API Detail](https://flowgram.ai/auto-docs/editor/functions/getNodeForm.html)
  4. ## Usage
  5. ```tsx pure
  6. // 1. BaseNode
  7. function BaseNode({ node }) {
  8. const form = getNodeForm(node);
  9. console.log(form.getValueIn('title'))
  10. return <div>{form?.render()}</div>
  11. }
  12. // 2. useNodeRender
  13. function BaseNode() {
  14. const { form } = useNodeRender();
  15. console.log(form.getValueIn('title'))
  16. return <div>{form?.render()}</div>
  17. }
  18. ```
  19. ## Return Inteface
  20. ```ts pure
  21. export interface NodeFormProps<TValues> {
  22. /**
  23. * The initialValues of the form.
  24. */
  25. initialValues: TValues;
  26. /**
  27. * Form values. Returns a deep copy of the data in the store.
  28. */
  29. values: TValues;
  30. /**
  31. * Form state
  32. */
  33. state: FormState;
  34. /**
  35. * Get value in certain path
  36. * @param name path
  37. */
  38. getValueIn<TValue = FieldValue>(name: FieldName): TValue;
  39. /**
  40. * Set value in certain path.
  41. * It will trigger the re-rendering of the Field Component if a Field is related to this path
  42. * @param name path
  43. */
  44. setValueIn<TValue>(name: FieldName, value: TValue): void;
  45. /**
  46. * set form values
  47. */
  48. updateFormValues(values: any): void;
  49. /**
  50. * Render form
  51. */
  52. render: () => React.ReactNode;
  53. /**
  54. * Form value change event
  55. */
  56. onFormValuesChange: Event<OnFormValuesChangePayload>;
  57. /**
  58. * Trigger form validate
  59. */
  60. validate: () => Promise<boolean>;
  61. /**
  62. * Form validate event
  63. */
  64. onValidate: Event<FormState>;
  65. /**
  66. * Form field value change event
  67. */
  68. onFormValueChangeIn<TValue = FieldValue, TFormValue = FieldValue>(
  69. name: FieldName,
  70. callback: (payload: onFormValueChangeInPayload<TValue, TFormValue>) => void
  71. ): Disposable;
  72. }
  73. ```