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

Add ability to make the <SaveButton> not disabled by default #5002

Merged
merged 12 commits into from
Jul 22, 2020

Conversation

Luwangel
Copy link
Contributor

@Luwangel Luwangel commented Jul 3, 2020

Implements #4913

To build this feature I allow the user to pass a new prop named alwaysEnableSaveButton to the <Toolbar> which forces enabling ou disabling the <SaveButton>. If the user doesn't specify this prop, we keep the classic behaviour by disabling the button until the form is dirty.

Todo

  • Allow the <SaveButton> to be disabled by passing the disabled prop
  • Create a new prop called alwaysEnableSaveButton in the <Toolbar> and implements its mechanism
  • Keep the condition pristine equals to disabled only if the alwaysEnableSaveButton prop has not been explicitly passed to the <Toolbar> but move the logic to the <Toolbar> instead of the <SaveButton> (possible breaking change here)
  • Fix and improve the documentation
  • Fix tests

Example

How to force enabling the <SaveButton> without rewriting the whole <Toolbar>:

import * as React from 'react';
import {
    Create,
    SimpleForm,
    Toolbar,
} from 'react-admin';
import PostReferenceInput from './PostReferenceInput';

export const CommentCreate = props => (
    <Create {...props}>
        <SimpleForm redirect={false} toolbar={<Toolbar alwaysEnableSaveButton />}>
            // Form goes here
        </SimpleForm>
    </Create>
);

If you don't pass the disabled prop, the behaviour "pristine equals to disabled" will be applied as before.

Screenshots

The following screenshots are outdated because the prop has changed. You need to use alwaysEnableSaveButton instead of disabled and invert the condition.

Force enabling the <SaveButton>

Sélection_006

Force disabling the <SaveButton>

Sélection_007

Keep the pristine equals to disabled mechanism

Sélection_008

@Luwangel Luwangel added breaking change RFR Ready For Review WIP Work In Progress and removed RFR Ready For Review labels Jul 3, 2020
Base automatically changed from next to master July 6, 2020 15:13
@Luwangel Luwangel changed the base branch from master to next July 15, 2020 11:41
@Luwangel Luwangel force-pushed the allow-to-override-save-button-disable-mecanism branch from a6ba1f2 to 756e23c Compare July 15, 2020 11:41
@Luwangel Luwangel added RFR Ready For Review and removed WIP Work In Progress labels Jul 17, 2020
@Luwangel Luwangel added this to the 3.8.0 milestone Jul 17, 2020
@Luwangel Luwangel force-pushed the allow-to-override-save-button-disable-mecanism branch from 223d110 to 722619e Compare July 22, 2020 09:04
@JulienMattiussi JulienMattiussi merged commit ac4f455 into next Jul 22, 2020
@JulienMattiussi JulienMattiussi deleted the allow-to-override-save-button-disable-mecanism branch July 22, 2020 12:36
@fzaninotto
Copy link
Member

Why is this a breaking change?

@Luwangel
Copy link
Contributor Author

Why is this a breaking change?

People who use directly the <SaveButton> cannot rely on the pristine prop anymore to disable the button. They have to use the disabled property instead. It's not a breaking change if they use the <SaveButton> inside the <Toolbar> or the <SimpleForm>.

So most of the time it's not a breaking change. But for some isolated cases, it could be one minor breaking change. It's better to mention it just in case.

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

Successfully merging this pull request may close these issues.

3 participants