Last active
February 16, 2018 13:17
-
-
Save cannap/ea1222568804d915c58db96cf43333b2 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
validate () { | |
let results = [] | |
if (this.schema.validator) { | |
results = results.concat( | |
...validator(this.schema.validator).map(validator => { | |
return validator.validate( | |
this.value, | |
this.schema, | |
this.model, | |
validator.message | |
) | |
}) | |
) | |
} | |
}, | |
export default function validate (fieldValidator) { | |
const rules = haye.fromPipe(fieldValidator.rules).toArray() | |
return rules.map(validator => { | |
if (!validators.hasOwnProperty(validator.name)) { | |
throw new Error(`Validator not found: ${validator.name}`) | |
} | |
const message = get(fieldValidator, `messages.${validator.name}`) | |
return { | |
validate: validators[validator.name], | |
args: validator.args, | |
message: message || defaultMessages[validator.name] | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment