【问题标题】:Wrapper component for admin-on-restadmin-on-rest 的包装器组件
【发布时间】:2017-11-03 13:43:22
【问题描述】:

我想从aor 创建一个包含InputsFields 的新组件,并在<SimpleForm><TabbedForm> 中使用它,如下所示:

const WrapperComp = () => {
  return (
    <div>
      <TextFieldLabel muiTheme={muiTheme}>Title Example</TextFieldLabel>,
      <TextInput source="status"/>,
      <TextField source="status"/>
    </div>
  )
} 

<SimpleForm>
  <WrapperComp />
</SimpleForm>

但我得到Uncaught Error: The TextInput component wasn't called within a redux-form &lt;Field&gt;. Did you decorate it and forget to add the addField prop to your component?

任何帮助将不胜感激。谢谢!

【问题讨论】:

    标签: reactjs admin-on-rest


    【解决方案1】:

    您需要使用 redux-form 中的 Field 来装饰您的 AOR 输入,并使用 AOR 中的 TextField 并传递 {...props} 所指出的 kunal pareek

    import React from 'react';
    import {
        LongTextInput,
        ImageField,
        ImageInput,
        TextField
    } from 'admin-on-rest';
    import { Field } from 'redux-form';
    
    
    const CustomGroupComp = (props) => (
        <div>
            <TextField source="status" {...props} />
            <Field name="staffComment" component={LongTextInput} label="staffComment" {...props}  />
            <Field name="adminComment" component={LongTextInput}  label="resources.faults.fields.adminComment" {...props} />
            <Field multiple name="fileA" component={ImageInput} accept="image/*">
                <ImageField source="path" title="title"/>
            </Field>
        </div>
    );
    
    export default CustomGroupComp;
    

    【讨论】:

    【解决方案2】:

    AOR SimpleForm 通过将 Redux-Form 属性传递给其子组件来工作。由于您正在包装组件,因此这些道具不会传递给您需要的组件。您现在需要明确地执行此操作。所以像

    const WrapperComp = (props) => {
      return (
        <div>
          <TextFieldLabel {...props} muiTheme={muiTheme}>Title Example</TextFieldLabel>,
          <TextInput {...props} source="status"/>,
          <TextField {...props} source="status"/>
        </div>
      )
    } 
    

    【讨论】:

    • 我也有这个问题,但是你的解决方案不能正常工作。它带有此错误:“在 redux-form 中未调用 TextInput 组件”
    • 尝试将 addField=true 作为 prop 传递给组件
    • 你的 AOR 版本是什么?
    • AOR 版本 1.3.2
    • AOR 的最新版本与我使用的版本相比有一些变化。以上可能行不通。但是尝试将 addField=true 作为 textInput 的道具并查看。
    猜你喜欢
    • 1970-01-01
    • 2017-02-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-21
    • 1970-01-01
    • 2018-03-09
    相关资源
    最近更新 更多