-
-
Notifications
You must be signed in to change notification settings - Fork 5.3k
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
Allow custom add and remove buttons in SimpleFormIterator #4818
Conversation
There was a problem hiding this 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 👍
@djhi I have done all the required changes, thanks for your suggestions. |
There was a problem hiding this 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)?
There was a problem hiding this 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 ?
I have added, two test cases to verify if add/remove buttons are not rendered if custom buttons are passed. It would be really helpful if you can mention the cases you want. |
Both :) |
Done, please review. |
@djhi any updates? |
@fzaninotto @djhi Any plans to merge this one? |
Any plans for this? It would help a lot. |
@NikolMarg I have done all the required changes. It should get merged now. |
There was a problem hiding this 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)
@Luwangel Done. Please let me know if anything else is required. |
Just one more thing. Could you rebase your PR against |
Sure, no issues. Done 👍 |
import { ArrayInput, SimpleFormIterator, DateInput, TextInput } from 'react-admin'; | ||
|
||
<ArrayInput source="backlinks"> | ||
<SimpleFormIterator addButton={<CustomAddButton />} addButton={<CustomRemoveButton />}> |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
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, |
@Luwangel Is there any way to get an example how a Edit: I guess its something like this for the // 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) |
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
Let me know if it requires any further updates.