Skip to content

Validations with dependentKeys do not work with change-set changes. #25

@arenoir

Description

@arenoir

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);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions