alibaba / x-render

🚴‍♀️ 阿里 - 很易用的中后台「表单 / 表格 / 图表」解决方案
https://xrender.fun
6.98k stars 988 forks source link

form.getValues() 获取不到 default 值 #1422

Closed JoelynZhou closed 11 months ago

JoelynZhou commented 11 months ago

最小复现 demo: https://codesandbox.io/s/youthful-estrela-qpmwr5?file=/App.tsx

import React from 'react';
import FormRender, { useForm } from 'form-render';

const schema = {
  type: 'object',
  displayType: 'row',
  properties: {
    input1: {
      title: '输入框 A',
      type: 'string',
      placeholder: '给输入框 B 赋值',
      default: "1",
    },
    input2: {
      title: '输入框 B',
      type: 'string',
      disabled: true
    },
  },
};

export default () => {
  const form = useForm();

  const values = form.getValues();
  console.log("values", values);

  const watch = {
    input1: val => {
      form.setValueByPath('input2', val);
    }
  };

  return (
    <FormRender 
      form={form} 
      schema={schema} 
      watch={watch} 
      labelWidth={200}
      maxWidth={400}
    />
  );
};

image

lhbxs commented 11 months ago

打印时机不对