fix validation bug in admin

This commit is contained in:
Josh Harvey 2017-05-04 01:22:04 +03:00
parent 9c0d21f66d
commit 1488a60a60
4 changed files with 29 additions and 16 deletions

View file

@ -44,10 +44,10 @@ function satisfiesRequire (config, cryptos, machineList, field, refFields) {
return isScopeEnabled(config, cryptos, machineList, refField, scope)
})
const isBlank = () => _.isNil(configManager.scopedValue(scope[0], scope[1], fieldCode, config))
const isBlank = _.isNil(configManager.scopedValue(scope[0], scope[1], fieldCode, config))
const isRequired = refFields.length === 0 || isEnabled()
return isRequired ? !isBlank() : true
return isRequired ? !isBlank : true
})
}
@ -78,8 +78,12 @@ function getGroup (fieldCode) {
return _.find(group => _.includes(fieldCode, group.fields), schema.groups)
}
function getField (group, fieldCode) {
if (!group) group = getGroup(fieldCode)
function getField (fieldCode) {
const group = getGroup(fieldCode)
return getGroupField(group, fieldCode)
}
function getGroupField (group, fieldCode) {
const field = _.find(_.matchesProperty('code', fieldCode), schema.fields)
return _.merge(_.pick(['cryptoScope', 'machineScope'], group), field)
}
@ -126,10 +130,11 @@ function validateRequires (config) {
return schema.groups.filter(group => {
return group.fields.some(fieldCode => {
const field = getField(group, fieldCode)
const field = getGroupField(group, fieldCode)
if (!field.fieldValidation.find(r => r.code === 'required')) return false
const refFields = _.map(_.partial(getField, null), field.enabledIf)
const refFields = _.map(_.partial(getField, group), field.enabledIf)
return !satisfiesRequire(config, cryptos, machineList, field, refFields)
})
})