cheetah-framework
Version:
Cheetah Framework JS used in all our applications
57 lines (54 loc) • 1.25 kB
JavaScript
export default {
props: {
errorPath: {
type: String,
default: null
}
},
computed: {
suffixedErrorPath () {
return this.errorPath ? (_.trim(this.errorPath, '.') + '.') : ''
}
},
methods: {
hasError (key, forceKey = false) {
return this.formErrors.has(
forceKey
? key
: this.suffixedErrorPath + key
) !== false
},
errorMessage (key, forceKey = false) {
return this.formErrors.get(
forceKey
? key
: this.suffixedErrorPath + key
)
},
errorMessages (path) {
return this.formErrors.getAll(path)
},
clearError (key, forceKey = false) {
this.formErrors.forget(
forceKey
? key
: this.suffixedErrorPath + key
)
},
addError (key, errors, forceKey = false) {
this.formErrors.add(
forceKey
? key
: this.suffixedErrorPath + key,
errors
)
},
/**
* return full path of fieldName containing formNamePrefix
* @param {String} fieldName
*/
getFieldName (fieldName) {
return this.suffixedErrorPath + fieldName
}
}
}