You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So why would I want to do this? I have this function which takes an aurelia-orm entity and creates some default validations for it based on the entity's orm metadata. Some basic validation for free is great!
exportfunctionentityValidationRules(entity){constmetadata=OrmMetadata.forTarget(entity);constassociations=metadata.fetch('associations');consttypes=metadata.fetch('types');constenumerations=metadata.fetch('enumerations');constdata=metadata.fetch('data');constmetadataKeys=[associations,types,enumerations].reduce((keys,obj)=>keys.concat(obj ? Object.keys(obj) : []),[]);returnmetadataKeys.reduce((ensure,key)=>{ensure=ValidationRules.ensure(key);if(data&&data[key]&&data[key].form&&data[key].form.label){console.log(data[key].form)ensure=ensure.displayName(data[key].form.label);}if(types&&types[key]){ensure=ensure.satisfies(satisfiesType(types[key])).withMessage(`${key} should be an ${types[key]}`);}if(enumerations&&enumerations[key]){ensure=ensure.satisfies(satisfiesEnumeration(enumerations[key])).withMessage(`${key} should be one of the following values ${humanEnumeration(enumerations[key])}`);}if(associations&&associations[key]){ensure=ensure.satisfies(satisfiesAssocation(associations[key]));}returnensure;},ValidationRules);}
I then return the last ensure return value and continue adding more rules.
I noticed that the current implementation
1.0.0-beta.1.0.1
does not allow me "merge" multiple rules/options for a property's validation.It ignores my previously defined displayName.
So why would I want to do this? I have this function which takes an aurelia-orm entity and creates some default validations for it based on the entity's orm metadata. Some basic validation for free is great!
I then return the last
ensure
return value and continue adding more rules.And now it ignores the validation options I defined in the
entityValidationRules
. Is that desired behavior?I could fix it by implementing entityValidationRules differently.
But I prefer using the API as it is documented.
The text was updated successfully, but these errors were encountered: