aurelia / validatejs

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

Can't set custom message on required property #48

Closed stevies closed 8 years ago

stevies commented 8 years ago

I have the latest 0.3.0 code. Can't set custom message on required property. I am trying this:

this.validator = new Validator(person);
this.validator.ensure('name').required({message: '^Enter your name'})      

Results in the default error message - Name can't be blank.

This works OK for format.

this.validator.ensure('name').format({ pattern: "[a-z0-9]+", flags: "i", message: "^Bad format"})    
apawsey commented 8 years ago

Just looked at the changes. This is because although changes were made to the validation rule class to ensure any configuration is being pushed through to validatejs, the same change wasn't made to the methods on the validator class. For example, here are the length, and required rules on the validator class.

length(configuration) {
    this.config.addRule(this.currentProperty, ValidationRule.lengthRule(configuration));
    return this;
  }
presence() {
    this.config.addRule(this.currentProperty, ValidationRule.presence());
    return this;
  }

and here is the corresponding static methods in the validation rule class:

static presence(config = true) {
    return new ValidationRule('presence', config);
  }
static lengthRule(config) {
    return new ValidationRule('length', config);
  }

The methods on the validator class are missing the handling of the configuration parameter, therefore they will never pass the configuration through, even though the validation rule itself would accept the configuration and pass it on to validatejs. Additionally we can't use the validation rule class directly as it's not exposed.

I'll see if I can submit a PR for this, although I'm already behind on my first planned submission haha

plwalters commented 8 years ago

Definitely let's get this fixed up my bust.

plwalters commented 8 years ago

Closed by https://github.com/aurelia/validatejs/pull/57