简体   繁体   English

react-admin 组件的问题

[英]Problems with react-admin components

I'm trying to use a TabbedShowLayout inside of Edit but this return a error related the missing props:我正在尝试在Edit中使用TabbedShowLayout ,但这会返回与缺少道具相关的错误:

print of the error打印错误

Here is my code:这是我的代码:

export const BarberEdit = (props) => {
  const [id, setId] = useState(props.id);
  const [name, setName] = useState("");
  const [phone, setPhone] = useState("");
  const [birthday, setBirthday] = useState(Date);
  const [transport, setTransport] = useState("");
  const [email, setEmail] = useState("");

  function handleSubmit() {
    console.log("alguma coisa.");
  }

  return (
    <Edit {...props} title={<BarberEditTitle />}>
      <TabbedShowLayout>
        <Tab label="Perfil">
          <SimpleForm submitOnEnter={false}>
            <TextInput source="name" />
            <TextInput source="phone" />
            <DateInput source="birthday" />
            <TextInput source="transport" />
            <TextInput source="email" />
          </SimpleForm>
        </Tab>

        <Tab label="Endereço">
          <ReferenceManyField
            label=""
            reference="barbers_addresses"
            target="barberId"
          >
            <Datagrid>
              <TextField source="street" label="Rua" />
              <TextField source="city" label="Cidade" />
              <TextField source="district" label="Bairro" />
            </Datagrid>
          </ReferenceManyField>
        </Tab>
      </TabbedShowLayout>
    </Edit>
  );
};

Reading the react-admin documentation a bit, i found that SimpleForm has two inherited properties.稍微阅读一下react-admin文档,我发现SimpleForm有两个继承的属性。

thanks in advance!提前致谢!

For Edit and Create layout, you should use TabbedForm, and not TabbedShowLayout, also, there is no need to use SimpleForm as Tab child, and you can pass submitOnEnter directly to TabbedForm对于Edit and Create layout,你应该使用TabbedForm,而不是TabbedShowLayout,另外,不需要使用SimpleForm作为Tab child,你可以直接将submitOnEnter传递给TabbedForm

export const BarberEdit = (props) => {
  const [id, setId] = useState(props.id);
  const [name, setName] = useState("");
  const [phone, setPhone] = useState("");
  const [birthday, setBirthday] = useState(Date);
  const [transport, setTransport] = useState("");
  const [email, setEmail] = useState("");

  function handleSubmit() {
    console.log("alguma coisa.");
  }

  return (
    <Edit {...props} title={<BarberEditTitle />}>
      <TabbedForm submitOnEnter={false}>
        <FormTab label="Perfil">
            <TextInput source="name" />
            <TextInput source="phone" />
            <DateInput source="birthday" />
            <TextInput source="transport" />
            <TextInput source="email" />
        </FormTab>

        <FormTab label="Endereço">
          <ReferenceManyField
            label=""
            reference="barbers_addresses"
            target="barberId"
          >
            <Datagrid>
              <TextField source="street" label="Rua" />
              <TextField source="city" label="Cidade" />
              <TextField source="district" label="Bairro" />
            </Datagrid>
          </ReferenceManyField>
        </FormTab>
      </TabbedForm>
    </Edit>
  );
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM