【问题标题】:defaultValue in AOR-dependent-inputAOR-dependent-input 中的 defaultValue
【发布时间】:2017-09-05 05:08:29
【问题描述】:

我想为 aor-dependent-input 中的字段设置 defaultValue, 我已经为ReferenceInput 设置了defaultValue,但是如何使用SubGenreInputDependentInput 设置defaultValue

这是我的代码:

<Create {...propsEdit} title=" " actions="">
<SimpleForm  redirect={"/caregiver/" + cid}>
    {/*<ReferenceArrayInput>*/}
    <DisabledInput source="user" defaultValue={cid} label="Caregiver ID"/>
    <ReferenceInput label="Centre" source="centre" defaultValue={this.props.record.student.centre.id} reference="centre" sort={{ field: 'name', order: 'ASC' }} allowEmpty>
        <SelectInput optionText="name" />
    </ReferenceInput>
    <DependentInput dependsOn="centre">
        <SubGenreInput source="current_group" optionText="label" optionValue="id" type="classgroup"/>
    </DependentInput>
    <DependentInput dependsOn="current_group" defaultValue={this.props.record.student.id}>
        <SubGenreInput source="student_id" optionText="fullname" optionValue="id" type="student"/>
    </DependentInput>
    {/*</ReferenceArrayInput>*/}
    <RadioButtonGroupInput source="account_type"  defaultValue={10} choices={[
        { id: 10, name: 'Caregiver' },
        { id: 20, name: 'Guardian' },
    ]} optionText="name" optionValue="id" />
    <TextInput source="relationship" label="Relationship"/>
</SimpleForm>

界面:

https://i.stack.imgur.com/wFHKC.png

//我不允许发布图片:(

【问题讨论】:

    标签: admin-on-rest


    【解决方案1】:

    这是一个已知问题,将在 admin-on-rest 的版本 1.3.0 中得到解决。同时,您可以使用此解决方法:

    <DependentInput source="appointmentTimeslot" dependsOn="planned" defaultValue={1}>
        <ReferenceInput source="appointmentTimeslot" reference="timeslots" allowEmpty={true} >
            <SelectInput optionText="name" optionValue="id" />
        </ReferenceInput>
    </DependentInput>
    

    请注意,我们在 DependentInput 组件及其子组件上都指定了 source。但是,defaultValue 仅在 DependentInput 组件上指定。

    如果您将多个子组件传递给 DependentInput 组件,此解决方法将不起作用。

    【讨论】:

      猜你喜欢
      • 2011-02-17
      • 2023-02-16
      • 2018-02-15
      • 2018-08-28
      • 1970-01-01
      • 2010-10-21
      • 1970-01-01
      • 1970-01-01
      • 2011-10-30
      相关资源
      最近更新 更多