AOR 相关输入中的默认值

defaultValue in AOR-dependent-input

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

DependentInput 设置默认值

这是我的代码:

<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

// 我不允许 post 图片 :(

这是一个已知问题,将在 admin-on-rest1.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 组件,此解决方法将不起作用。