Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Dynamically build Aurelia Validation rules.
//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])
}
});
{
"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
You can’t perform that action at this time.