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

Allow custom add and remove buttons in SimpleFormIterator #4818

Conversation

manishsundriyal
Copy link
Contributor

As mentioned in #4676

This is an enhancement that will allow us to pass our own custom add and remove buttons to the SimpleFormIterator component.

Changes

  • feature: add addButton and removeButton as props in SimpleFormIterator
  • refactor: moved the add and remove button logic to separate functions
  • test cases: added test cases for addButton and removeButton props
  • docs: added an example of the same in docs

Let me know if it requires any further updates.

Copy link
Contributor

@djhi djhi left a comment

Choose a reason for hiding this comment

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

Thanks for working on this 👍

packages/ra-ui-materialui/src/form/SimpleFormIterator.js Outdated Show resolved Hide resolved
packages/ra-ui-materialui/src/form/SimpleFormIterator.js Outdated Show resolved Hide resolved
packages/ra-ui-materialui/src/form/SimpleFormIterator.js Outdated Show resolved Hide resolved
@manishsundriyal manishsundriyal requested a review from djhi May 20, 2020 12:23
@manishsundriyal
Copy link
Contributor Author

@djhi I have done all the required changes, thanks for your suggestions.

Copy link
Contributor

@djhi djhi left a comment

Choose a reason for hiding this comment

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

Looks pretty good. Can you please add tests to ensure that the SimpleFormIterator still work correctly when using custom buttons (their onClick is bound correctly)?

packages/ra-ui-materialui/src/form/SimpleFormIterator.js Outdated Show resolved Hide resolved
packages/ra-ui-materialui/src/form/SimpleFormIterator.js Outdated Show resolved Hide resolved
packages/ra-ui-materialui/src/form/SimpleFormIterator.js Outdated Show resolved Hide resolved
@manishsundriyal manishsundriyal requested a review from djhi May 20, 2020 14:00
Copy link
Contributor

@djhi djhi left a comment

Choose a reason for hiding this comment

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

Looks good. Can you add some tests to verify items are added/removed when using custom buttons with an onClick specified ?

@manishsundriyal
Copy link
Contributor Author

Looks good. Can you add some tests to verify items are added/removed when using custom buttons with an onClick specified ?

I have added, two test cases to verify if add/remove buttons are not rendered if custom buttons are passed.
Just to confirm, you want me to add test cases to verify if custom add/remove buttons are rendered when passed as props.
or is this related to verify if action is performed onClick event? or both?

It would be really helpful if you can mention the cases you want.

@djhi
Copy link
Contributor

djhi commented May 20, 2020

Both :)

@manishsundriyal manishsundriyal requested a review from djhi May 20, 2020 18:25
@manishsundriyal
Copy link
Contributor Author

Both :)

Done, please review.

@manishsundriyal
Copy link
Contributor Author

@djhi any updates?

@manishsundriyal
Copy link
Contributor Author

@fzaninotto @djhi Any plans to merge this one?

@NikolMarg
Copy link

Any plans for this? It would help a lot.

@manishsundriyal
Copy link
Contributor Author

@NikolMarg I have done all the required changes. It should get merged now.

Copy link
Contributor

@Luwangel Luwangel left a comment

Choose a reason for hiding this comment

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

Great job! 👍 I just posted a few improvements (typo, rewriting)

docs/Inputs.md Outdated Show resolved Hide resolved
@manishsundriyal
Copy link
Contributor Author

@Luwangel Done. Please let me know if anything else is required.

@Luwangel
Copy link
Contributor

Just one more thing. Could you rebase your PR against next instead of master (change the base branch)? We'll publish your code in the next major version 3.8.0 because it introduces a new feature.

@Luwangel Luwangel added this to the 3.8.0 milestone Jul 27, 2020
@manishsundriyal manishsundriyal changed the base branch from master to next July 27, 2020 15:05
@manishsundriyal
Copy link
Contributor Author

Sure, no issues. Done 👍

@Luwangel Luwangel merged commit 6e67a8a into marmelab:next Jul 27, 2020
@Luwangel Luwangel changed the title enhancement: allow custom add and remove buttons in SimpleFormIterator Allow custom add and remove buttons in SimpleFormIterator Jul 27, 2020
@Luwangel Luwangel added the RFR Ready For Review label Jul 27, 2020
import { ArrayInput, SimpleFormIterator, DateInput, TextInput } from 'react-admin';

<ArrayInput source="backlinks">
<SimpleFormIterator addButton={<CustomAddButton />} addButton={<CustomRemoveButton />}>
Copy link
Member

Choose a reason for hiding this comment

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

there is a typo here, I read addButton twice

Copy link
Contributor

Choose a reason for hiding this comment

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

Oops, we missed it. I opened the PR #5095 to fix it.

@roshi112
Copy link

roshi112 commented Mar 6, 2021

Hello I am new to git can someone please let me know where are the docs for the same ??

thanks in advance

@Luwangel
Copy link
Contributor

Luwangel commented Mar 8, 2021

Hello I am new to git can someone please let me know where are the docs for the same ??

thanks in advance

Hi,

You can find the complete documentation on react-admin's website: https://marmelab.com/react-admin/Inputs.html#arrayinput.

Regards,
Adrien

@Maybach91
Copy link

Maybach91 commented Mar 10, 2021

@Luwangel Is there any way to get an example how a <CustomAddButton/> or <CustomRemoveButton/> should look like to get it work? The only information about this is a button to create a new entry with pre-filled information (reference). Unfortunately the documentation for Record Buttons is empty. :(

Edit:

I guess its something like this for the <CustomAddButton/>:

// Imports required for CustomAddButton
import { Button } from "@material-ui/core";
import AddIcon from "@material-ui/icons/AddCircleOutline";

// Custom Buttom
const CustomAddButton = (props: any) => {
  return (
    <Button size="medium" variant="contained" color="secondary" {...props}>
      <AddIcon />
      Add new Question
    </Button>
  );
};
// Usage
<SimpleFormIterator addButton={<CustomAddButton {...props} />}>...</SimpleFormIterator>

Is there any way to pre fill some of the Input as well on click? Like i want to generate an custom ID field, which saves into the database. Currently it just generates the ID ones and all the defaultValues are the same, but i have a randomize function based on time on this value.

Edit2: Okay, its not possible to have these functions as Initial Values on the Input itself (reference)

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

Successfully merging this pull request may close these issues.

None yet

8 participants