Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Default SimpleFormIterator Push Value #4394

Conversation

jdemangeon
Copy link
Contributor

@jdemangeon jdemangeon commented Feb 5, 2020

Closes #2489
Closes #3249

When we use the SimpleFormIterator inside an array of scalar values (ArrayInput) displayed as TextInput, the famous [Object object] value is displayed on "+ Add" click.

Example:

import { SimpleFormIterator } from "react-admin";

/* recipients = ["foo@bar.com", "bar@foo.com", ....] */

<ArrayInput source="recipients">
      <SimpleFormIterator>
          <TextInput />
      </SimpleFormIterator>
</ArrayInput>

Results to:

image

So, to avoid this, we should inject undefined instead of an empty {}.

Here is a temporary workaround for those who are having the same problem:

import React from "react";
import { SimpleFormIterator } from "react-admin";

export const SimpleFormIteratorWithUndefinedDefault = props => {
  const originPush = props.fields.push;
  props.fields.push = data =>
    originPush(JSON.stringify(data) === "{}" ? undefined : data);

  return <SimpleFormIterator {...props} />;
};

PS: This "display" is the default one used in ApiPlatform Admin for the array field type (https://github.com/api-platform/admin/blob/master/src/InputGuesser.js#L90)

@jdemangeon jdemangeon added the RFR Ready For Review label Feb 5, 2020
@jdemangeon
Copy link
Contributor Author

Oops, i've seen that another PR covering this issue (https://github.com/marmelab/react-admin/pull/4306/files).

@jdemangeon jdemangeon closed this Feb 5, 2020
@jdemangeon jdemangeon reopened this Feb 17, 2020
@JulienMattiussi JulienMattiussi self-requested a review March 2, 2020 14:35
Copy link
Contributor

@JulienMattiussi JulienMattiussi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unit tests ok
Manual tests ok

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
RFR Ready For Review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ArrayInput does not like primitive values defaultValue of Inputs inside ArrayInput not working
3 participants