Last active
October 11, 2016 21:08
-
-
Save singledigit/36c07af90bf34d6be1aedfcf5590b275 to your computer and use it in GitHub Desktop.
Dynamically build Aurelia Validation rules.
This file contains 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
//This is a rough attempt at dynamically building validation rules based on a JSON document. | |
let rules = []; | |
Forms[this.viewing].map(field => { | |
if(field.required && !field.viewIf){ | |
rules.push(ValidationRules.ensure(field.propName).required().rules[0]) | |
} | |
if (field.required && field.viewIf) { | |
rules.push(ValidationRules.ensure(field.propName).required() | |
.when(val => this.currentDoc[field.viewIf] === field.viewIfValue) | |
.rules[0]) | |
} | |
}); |
This file contains 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
{ | |
"fieldDescription": "Dashboard Link", | |
"fieldType": "link-field", | |
"propName": "dashboardLink", | |
"viewIf": "previousProperty", | |
"viewIfValue": true, | |
"required": true | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment