aurelia / validatejs

Enables expressive validation using decorators and/or a fluent API.
MIT License
22 stars 23 forks source link

ValidateObject bug #111

Closed adarshpastakia closed 8 years ago

adarshpastakia commented 8 years ago

I'm submitting a bug report

Please tell us about your environment:

Current behavior:

Expected/desired behavior:

i have created a vaildatemap validation rule which iterates a map and validates each object

const validator = new Validator();
validate.validators.map = function(map: Map<string, any>) {
    const errors = []
    map.forEach((v, k) => {
        if (validator.validateObject(v).length > 0) errors.push(k);
    });
    // Unfortunately details are lost, but Aurelia's controller will evaluate and display them on the binding as well.
    // This is only really useful for your `validate()` call when saving.
    return errors.length > 0 ? `${errors.join(',')} has invalid values` : null;
}

function mapRule(config) {
    return new ValidationRule('map', config);
}
export function validatemap(targetOrConfig?, key?, descriptor?) {
    return base(targetOrConfig, key, descriptor, mapRule);
}

unfortunately the validateObject keeps failing because propertyName is null.

propertyName = propertyName || ruleInfo.key;
if (propertyName !== null && ruleInfo.key !== propertyName) {
   continue;
}
heruan commented 8 years ago

I confirm, this currently fails:

let validator = new Validator();
let foo = { foo: "bar" };
let rules = new ValidationRules().ensure("foo").presence(true);
let errors = validator.validateObject(foo, rules);
console.log(errors);
// results in this ValidationError:
{
    message: "Null can't be blank",
    object: { foo: "bar" },
    propertyName: null,
    rule: {
        name: "presence",
        config: true
    }
}

https://github.com/aurelia/validatejs/pull/116 implements @adarshpastakia fix for this.

jdanyow commented 8 years ago

closing- validatejs was dropped in last release