marmelab / aor-dependent-input

A component for displaying input depending on other inputs values in Admin-on-rest
MIT License
60 stars 12 forks source link

Dependent input when both resources are based on the REST client and have a 'belongsTo' relationship? #22

Open afilp opened 6 years ago

afilp commented 6 years ago

Hi,

I checked your example with your outer fetch, but I do not understand how to achieve a dependent input for a sub-resource, through AOR stateless functions (or not). The use case is that we want the "subCategories" field to be populated based on the "categories" field, to which there is a 'belongsTo' relationship.

    <Create title={<TitleCreate />}{...props}>
        <SimpleForm validate={validateCreateEdit}>

            <ReferenceInput label="CATEGORY" source="cat_id" reference="categories" allowEmpty
                            perPage={100}
                            sort={{field: 'name', order: 'ASC'}}
            >
                <SelectInput optionText="name" />
            </ReferenceInput>

            <ReferenceInput label="SUBCATEGORY" source="subCat_id" reference="subCategories" allowEmpty
                            perPage={100}
                            sort={{field: 'name', order: 'ASC'}}
            >
                <SelectInput optionText="name" />
            </ReferenceInput>

        </SimpleForm>
    </Create>

This is the relationship:

  "relations": {
    "category": {
      "type": "belongsTo",
      "model": "category",
      "foreignKey": "cat_id"
    }
  }

I do not understand how this can be done based on the above generic AOR code.

Thanks for any hints or added documentation!

afilp commented 6 years ago

@djhi Is it possible to let me know if this is supported?