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

fix(Form): don't prevent form submission when action='' #2165

Merged
merged 3 commits into from
Oct 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/collections/Form/Form.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ class Form extends Component {

// Heads up! Third party libs can pass own data as first argument, we need to check that it has preventDefault()
// method.
if (!action) _.invoke(e, 'preventDefault')
if (typeof action !== 'string') _.invoke(e, 'preventDefault')
_.invoke(this.props, 'onSubmit', e, this.props, ...args)
}

Expand Down
11 changes: 10 additions & 1 deletion test/specs/collections/Form/Form-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,13 @@ describe('Form', () => {
shallow(<Form />)
.simulate('submit', event)

event.preventDefault.should.have.been.calledOnce()
shallow(<Form action={false} />)
.simulate('submit', event)

shallow(<Form action={null} />)
.simulate('submit', event)

event.preventDefault.should.have.been.calledThrice()
})

it('does not prevent default on the event when there is an action', () => {
Expand All @@ -76,6 +82,9 @@ describe('Form', () => {
shallow(<Form action='do not prevent default!' />)
.simulate('submit', event)

shallow(<Form action='' />)
.simulate('submit', event)

event.preventDefault.should.not.have.been.called()
})

Expand Down