Merge pull request #899 from dod-ccpo/fix-application-form-errors

Only show first error message on application form
This commit is contained in:
richard-dds 2019-06-12 15:08:40 -04:00 committed by GitHub
commit 6911eff35e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,5 +1,6 @@
import FormMixin from '../../mixins/form' import FormMixin from '../../mixins/form'
import textinput from '../text_input' import textinput from '../text_input'
import * as R from 'ramda'
const createEnvironment = name => ({ name }) const createEnvironment = name => ({ name })
@ -34,14 +35,14 @@ export default {
func: this.hasEnvironments, func: this.hasEnvironments,
message: 'Provide at least one environment name.', message: 'Provide at least one environment name.',
}, },
{
func: this.envNamesAreUnique,
message: 'Environment names must be unique.',
},
{ {
func: this.environmentsHaveNames, func: this.environmentsHaveNames,
message: 'Environment names cannot be empty.', message: 'Environment names cannot be empty.',
}, },
{
func: this.envNamesAreUnique,
message: 'Environment names must be unique.',
},
], ],
errors: [], errors: [],
environments, environments,
@ -66,13 +67,14 @@ export default {
}, },
validate: function() { validate: function() {
this.errors = this.validations // Only take first error message
.map(validation => { this.errors = R.pipe(
if (!validation.func()) { R.map(validation =>
return validation.message !validation.func() ? validation.message : undefined
} ),
}) R.filter(Boolean),
.filter(Boolean) R.take(1)
)(this.validations)
}, },
hasEnvironments: function() { hasEnvironments: function() {