Skip to content

Commit

Permalink
double checked sync errors before submit. might fix #156. v2.4.3
Browse files Browse the repository at this point in the history
  • Loading branch information
erikras committed Oct 21, 2015
1 parent 51b1617 commit 1ad1a71
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 26 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "redux-form",
"version": "2.4.2",
"version": "2.4.3",
"description": "A higher order component decorator for forms using Redux and React",
"main": "./lib/index.js",
"repository": {
Expand Down
53 changes: 28 additions & 25 deletions src/createReduxForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function silenceEvents(fn) {
};
}

function isAsyncValid(errors) {
function hasErrors(errors) {
return !errors || Object.keys(errors).reduce((valid, error) => valid && isValid(errors[error]), true);
}

Expand Down Expand Up @@ -185,7 +185,7 @@ export default function createReduxForm(isReactNative, React) {
}
const handleErrors = asyncErrors => {
dispatch(actions.stopAsyncValidation(asyncErrors));
return isAsyncValid(asyncErrors);
return hasErrors(asyncErrors);
};
return promise.then(handleErrors, handleErrors);
}
Expand Down Expand Up @@ -242,30 +242,33 @@ export default function createReduxForm(isReactNative, React) {
event.stopPropagation();
}
const values = this.getValues();
const submitWithPromiseCheck = () => {
const result = submit(values);
if (result && typeof result.then === 'function') {
// you're showing real promise, kid!
dispatch(actions.startSubmit());
return result.then(submitResult => {
dispatch(actions.stopSubmit());
return submitResult;
}, submitError => {
dispatch(actions.stopSubmit(submitError));
return submitError;
});
}
};
dispatch(actions.touch(...fields));
if (allValid) {
if (asyncValidate) {
return this.runAsyncValidation(actions, values).then(asyncValid => {
if (allValid && asyncValid) {
return submitWithPromiseCheck(values);
}
});
const syncErrors = this.runSyncValidation(values);
if (!hasErrors(syncErrors)) {
const submitWithPromiseCheck = () => {
const result = submit(values);
if (result && typeof result.then === 'function') {
// you're showing real promise, kid!
dispatch(actions.startSubmit());
return result.then(submitResult => {
dispatch(actions.stopSubmit());
return submitResult;
}, submitError => {
dispatch(actions.stopSubmit(submitError));
return submitError;
});
}
};
dispatch(actions.touch(...fields));
if (allValid) {
if (asyncValidate) {
return this.runAsyncValidation(actions, values).then(asyncValid => {
if (allValid && asyncValid) {
return submitWithPromiseCheck(values);
}
});
}
return submitWithPromiseCheck(values);
}
return submitWithPromiseCheck(values);
}
};
if (typeof submitOrEvent === 'function') {
Expand Down

0 comments on commit 1ad1a71

Please sign in to comment.