react-admin
react-admin copied to clipboard
Global validation doesn't work in TabbedForm
What you were expecting: Global validation prevents creation of new item according set validation rules.
What happened instead: Item could be created even in the situation when global validation rules were not met.
Steps to reproduce:
- Set global validation function to
TabbedFormwith at least 2 tabs. - Add global and local validation rules, e.g. field not empty on first tab.
- No validation rules on second tab.
- Try to Create/Save item when on second tab.
Related code:
In examples/demo/src/products/index.js:
const validateProductCreate = (values) => {
const errors = {};
if (!values.image) {
errors.image = ['image is required'];
}
...
return errors;
};
export const ProductCreate = withStyles(
createStyles
)(({ classes, ...props }) => (
<Create {...props}>
<TabbedForm validate={validateProductCreate}>
...
Product can be created when on 'Description' tab.
Environment
- React-admin version: 2.0.2
- React version: 16.3.1
- Browser: any
Bug confirmed and reproduced
This seems to be caused by a bug in redux-form (see link above). Unfortunately, we can't circumvent it in react-admin... Except by rendering all tabs and hiding the ones not in focus using CSS.