react-admin: ArrayInput not working with parse and format functions

What you were expecting: Behavior described here https://marmelab.com/react-admin/Inputs.html#transforming-input-value-tofrom-record with ArrayInput

What happened instead: parse and format functions not called

Steps to reproduce: ArrayInput with parse and format functions passed as props, as decribed here https://marmelab.com/react-admin/Inputs.html#transforming-input-value-tofrom-record

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 19 (13 by maintainers)

Commits related to this issue

Most upvoted comments

I understand that it might not be react-admin fault if we can’t use format() and parse(), but I think the doc should at least explain that it doesn’t work, otherwise it will only lead to more confusion.

The doc currently says:

<ArrayInput> also accepts the common input props.

_https://marmelab.com/react-admin/Inputs.html#arrayinput_

If you only need the format attribute on ArrayInput, you can extend it like so:

const MyArrayInput = (props) => {
  useEffect(() => {
    //transform your source with some function e.g.
    //props.record[props.source] = transform(props.record[props.source]);
  }, [props.record]);

  return (
    <ArrayInput {...props}>
      //your fields here
    </ArrayInput>
  );
}

@Kmaschta sorry i’ve just remembered better the whole thing, so i wanted to use the parse and format because i wanted my user to choose which fields on a record he’d populate, we’re talking object to array format here, transforming an object structure to an array of keys of that object with dynamic field types for each key. I ended up writing a “DynamicObjectEditor”, which is not exactly an array input, It assumes from the getgo the source he’s editing is an object. So I’m not sure if it’d be a solution for this case?

edit: this will take some time to clean up, i might as well rewrite it now since i was going to anyway, i’ll proceed and clean up right now if you guys are still interested

@Pierre-Demessence You’re right, I made a slight modification to the documentation in 46ebc96 to avoid the confusion.

It seems redux-form’s FieldArray, which is user internally by ArrayInput, doesn’t support parse and format either. So there is nothing we can do in react-admin to fix that.

https://redux-form.com/8.2.0/docs/api/fieldarray.md/

So the problem is on their side. I suggest you open an issue in their bug tracker.