DependsOn not working
What you were expecting:
<DependsOn> is working as described in documentation.
What happened instead:
<DependsOn> is causing error and blank page.
Related code:
<DependsOn source="name" value="abstract">
<TextField source="name">
</DependsOn>
applied in next branch demo project.
Environment
- react-admin: 2.0.0-beta4
- React: 16.2.0

Are you using it in a form or in a list/show view? Can you provide more context?
@fzaninotto: Sorry, here's more detailed example from demo src/categories/index.js:
export const CategoryList = withStyles(listStyles)(({ classes, ...props }) => (
<List {...props} sort={{ field: 'name', order: 'ASC' }}>
<Datagrid>
<TextField source="name" className={classes.name} />
<LinkToRelatedProducts />
<DependsOn source="name" value="abstract">
<TextField source="name" />
</DependsOn>
<EditButton />
</Datagrid>
</List>
));
Note that also using resolve function causes the same.
The current DependsOn implementation requires a redux-form to be declared higher in the component hierarchy, so it doesn't work in List and Show views.
But I'm wondering if we need to provide a special component for conditional field, as it's already possible using a simple:
const ConditionalTextField = ({ record, ...props }) => record.name == 'abstract' ? <TextField source="name" record={record} {...props} /> : null;
ConditionalTestField.defaultProps: {
addLabel: true,
};
@djhi, any opinion?
Agreed
Not that simple: the addLabel should be conditional, too...
It seems that the DependentField in ra-dependent-input didn't work either, since it used <FormField> in a formless environment...
Fixed by #1748
@fzaninotto there is an example for how to do this on ?
I can't seem to figure it out. Thanks.
Fyi, I tried the following:
const ConditionalOrganisation = ({ record, ...rest }) => {
if (record && 'CUSTOM' === record.type) {
return (
<ReferenceField label="Organisation" source="organisation" reference="organisations" record={record} {...rest}>
<TextField source="name" />
</ReferenceField>
);
}
return null;
}
It seems like it may just be an issue with the ReferenceField and this method?
Please stop asking this kind of questions on issues, especially closed ones. Use Stack overflow for that.