-
Notifications
You must be signed in to change notification settings - Fork 10
Open
Description
IMO the best feature of the cp-validations addon is the ability to conditionally validate attributes based on other attribute values. This feature is lost when the validate function is built. I am thinking a separate Object needs to be created with the validations and all changes applied to it within the validate function.
Something like:
export default function createValidatableChangeset(model, validationsMixin) {
let validatableChangeset = Ember.Object.extend(validationsMixin).create();
let validationMap = validatableChangeset.get('validations.validatableAttributes').reduce((o, attr) => {
o[attr] = true;
return o;
}, {});
function validateFn({ key, newValue, oldValue, changes, content }) {
validatableChangeset.setProperties(changes);
return validatableChangeset.validateAttribute(key, newValue).then(({ validations }) => {
return validations.get('isValid') ? true : validations.get('message');
});
}
return new Changeset(model, validateFn, validationMap);
}
drewchandler, bgentry, SergeAstapov, rickieshi and DropsOfSerenity
Metadata
Metadata
Assignees
Labels
No labels