decorators for validations
Well, I'm currently working on decorators for aurelia validation. At the moment, I have the following code working:
export class ClientViewModel {
public Id: string;
@required()
public Name: string;
@displayName("Identity")
@email("It's not an valid email")
@satisfiesRule("cpfcnpj")
@required()
public PersonIdentity: string;
constructor(data: any = {}) {
this.Id = data.Id || null;
this.Name = data.Name || null;
this.PersonIdentity = data.PersonIdentity || null;
}
}
After I'm done, would you guys be interested in accept a PR?
It's gonna be very easy to make a validation in a model with this implementation! @EisenbergEffect
@iuribrindeiro that'd be awesome.
Here are some issues where you can get some more ideas to implement it (not listed in any order)
- https://github.com/aurelia/validation/issues/287
- https://github.com/aurelia/validation/pull/330
Awesome,@bigopon! I'll open a PR soon for that :)
Hey, @bigopon, can you help me create a PR? I should create a branch and then create a PR to develop?
@iuribrindeiro, nice idea! Just some proposals:
-
Don't forget about the localization! I have two variants on how to interface it: 1.1. Use an options container as a decorator's parameter, e.g. @email ({messageKey: "the_email_has_wrong_format", fallbackMessage: "The email...", ....}) 1.2. or... to make an additional attribute, something like as @messageKey("the_email_has_wrong_format")
-
To add as a parameter/attribute the trigger param about when to validate: on blur, on every change, or something else. And that must be per binding.