Only show first error message on application form
This commit is contained in:
parent
e554845407
commit
4fdbc5b4cb
@ -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,12 @@ 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) => !validation.func() ? validation.message : undefined),
|
||||||
return validation.message
|
R.filter(Boolean),
|
||||||
}
|
R.take(1)
|
||||||
})
|
)(this.validations)
|
||||||
.filter(Boolean)
|
|
||||||
},
|
},
|
||||||
|
|
||||||
hasEnvironments: function() {
|
hasEnvironments: function() {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user