diff --git a/docs.md b/docs.md index 69a4ffd..b6d4fee 100644 --- a/docs.md +++ b/docs.md @@ -12,6 +12,7 @@ A wrapper around the `reduxForm` HOC exported from 1. Makes extra options available for configuring the form 2. Wraps every rejected `onSubmit` in a `SubmissionError`. If the thrown error has an `errors` property, its value will be passed to `SubmissionError`. +3. Provides a default `onSubmit` function that resolves successfully and logs a warning. The extra options that can be provided to `lpForm` are as follows: diff --git a/src/lp-form.js b/src/lp-form.js index 6a83066..7d0385d 100644 --- a/src/lp-form.js +++ b/src/lp-form.js @@ -1,6 +1,10 @@ import React from 'react' import { reduxForm } from 'redux-form' -import { createFilterFunction, wrapSubmissionPromise, wrapDisplayName } from './utils' +import { + createFilterFunction, + wrapSubmissionPromise, + wrapDisplayName, +} from './utils' import validate from './validate' /** @@ -9,6 +13,7 @@ import validate from './validate' * * 1. Makes extra options available for configuring the form * 2. Wraps every rejected `onSubmit` in a `SubmissionError`. If the thrown error has an `errors` property, its value will be passed to `SubmissionError`. + * 3. Provides a default `onSubmit` function that resolves successfully and logs a warning. * * The extra options that can be provided to `lpForm` are as follows: * @@ -45,6 +50,12 @@ import validate from './validate' * */ + function defaultOnSubmit (...args) { + // eslint-disable-next-line no-console + console.warn('WARNING: no onSubmit function specified. Form will submit successfully by default.') + return Promise.resolve(...args) + } + function lpForm (options={}) { return Wrapped => { const WrappedWithForm = reduxForm()(Wrapped) @@ -53,7 +64,7 @@ function lpForm (options={}) { const { name, initialValues, - onSubmit, + onSubmit=defaultOnSubmit, submitFilters, initialValuesFilters, constraints={}, diff --git a/test/lp-form.test.js b/test/lp-form.test.js index 1468d09..5561a14 100644 --- a/test/lp-form.test.js +++ b/test/lp-form.test.js @@ -57,6 +57,18 @@ test('lpForm: wraps rejected promises in a SubmissionError', () => { }) }) +test('lpForm: provides a default onSubmit that submits successfully', () => { + expect.assertions(1) + const Wrapped = () =>
Hi
+ const Form = lpForm()(Wrapped) + const wrapper = mount(
) + const formConfig = wrapper.find(Wrapped).props() + + return formConfig.onSubmit(INITIAL_VALUES).then(values => { + expect(values).toEqual(INITIAL_VALUES) + }) +}) + test('lpForm: creates validation function with constraints', () => { const constraints = { 'foo': { presence: true } } const Wrapped = () =>
Hi