Skip to content

Instantly share code, notes, and snippets.

@ndelitski
Last active November 24, 2017 22:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ndelitski/c9f85a2718d4b3580bc461e26a5a4c37 to your computer and use it in GitHub Desktop.
Save ndelitski/c9f85a2718d4b3580bc461e26a5a4c37 to your computer and use it in GitHub Desktop.
const formErrors = {
budget: {
amount: 'Required',
},
project: {
name: 'Required',
},
empty: null,
}
R.pipe(
R.toPairs,
R.filter(R.last),
// TODO use ramda here!
forms => [
// stop submit for every form
R.map(R.apply(stopSubmitForm))(forms),
// focus for first form error
R.pipe(
R.head,
([form, errors]) => [form, R.head(R.keys(errors))],
R.apply(focusFormField)
)(forms),
],
R.flatten
)(formErrors)
// should output stopSubmitForm('budget'), stopSubmit('project'), focus('budget', 'amount')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment