Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cutomize Delete button react-admin

Is there any way to customise DeleteButton button in react-admin to add a confirmation message like 'Do you want to delete item?'. Currently on clicking on DeleteButton it directly deletes the item without asking for a confirmation. I tried adding title attribute to delete button but it does not get fired. Here is my code

//This worked with admin-on-rest, but not working with react-admin
const CategoryDeleteTitle = translate(({ record, translate }) => <span>
        {translate('Delete')}&nbsp;
        {record && `${record.code} ${record.name}`}
    </span>);

const EditActions = ({ basePath, data, resource }) => (
    <CardActions>
        <ShowButton basePath={basePath} record={data} />
        <ListButton basePath={basePath} />
        <DeleteButton title={<CategoryTitle />} basePath={basePath} record={data} resource={resource} />

    </CardActions>
);

export const CategoryEdit = (props) => (
    <Edit actions={<EditActions />} title={<CategoryTitle />} {...props}>
        <SimpleForm>
            <DisabledInput source="id" />
            <TextInput source="name" />
        </SimpleForm>
    </Edit>
);
like image 869
Chetan Gawai Avatar asked Jul 15 '26 19:07

Chetan Gawai


2 Answers

We now handle deletions in an optimistic way, providing an undo mechanism instead of a confirmation dialog.

If this doesn't suit you, you can follow the UPGRADE GUIDE which leads to this page of the documentation: https://marmelab.com/react-admin/CreateEdit.html#actions

Note that you'll have to create and handle your confirmation dialog using something like react-modals and dispatch the DELETE action yourself.

like image 55
Gildas Garcia Avatar answered Jul 21 '26 13:07

Gildas Garcia


You can use this gist with custom actions like:

const UserEditActions = ({ basePath, data, resource }) => (
    <CardActions>
        <ListButton basePath={basePath} />
        <DeleteButtonWithConfirmation basePath={basePath} record={data} resource={resource} undoable={false} />
        <RefreshButton />
      </CardActions>
    );

export const UserEdit = ({ ...props }) => (
  <Edit {...props} actions={<UserEditActions />} >
    <CreateEditForm title={<EntityTitle label="User" />} />
  </Edit>
);
like image 22
Ady Levy Avatar answered Jul 21 '26 11:07

Ady Levy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!