Skip to content

Commit

Permalink
fix 'smart' SubmitButton behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
jannikbuschke committed Feb 29, 2020
1 parent 78a950b commit 2e3cdda
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ function App() {
```

The `SubmitButton` and `ResetButton` will disable automatically depending on form state. The `ResetButton` is enabled if the form is dirty. The `SubmitButton` is enabled if the form is valid or if it is not dirty.
If you do want to control the disable behavior yourself you can provide the (usual ant design) `disable: boolean` prop.
I.e. `<SubmitButton disabled={false} />` will make the button always be enabled.

## Form- and Field-level Validation

Expand Down
4 changes: 2 additions & 2 deletions src/submit-button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import { ButtonProps } from 'antd/lib/button'

export const SubmitButton = ({ children, ...restProps }: ButtonProps) => (
<Field>
{({ form: { isSubmitting, isValid, dirty } }: FieldProps) => (
{({ form: { isSubmitting, isValid, dirty, submitCount } }: FieldProps) => (
<Button
loading={isSubmitting}
type='primary'
htmlType='submit'
disabled={!isValid && dirty}
disabled={!isValid && (dirty || submitCount > 0)}
{...restProps}
>
{children}
Expand Down

0 comments on commit 2e3cdda

Please sign in to comment.