react-admin icon indicating copy to clipboard operation
react-admin copied to clipboard

Global validation doesn't work in TabbedForm

Open zavadpe opened this issue 8 years ago • 2 comments

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:

  1. Set global validation function to TabbedForm with at least 2 tabs.
  2. Add global and local validation rules, e.g. field not empty on first tab.
  3. No validation rules on second tab.
  4. 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

zavadpe avatar May 30 '18 12:05 zavadpe

Bug confirmed and reproduced

fzaninotto avatar Jun 05 '18 12:06 fzaninotto

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.

fzaninotto avatar Jun 05 '18 12:06 fzaninotto