aurelia / validation

A validation plugin for Aurelia.
MIT License
132 stars 129 forks source link

decorators for validations #523

Open iuribrindeiro opened 5 years ago

iuribrindeiro commented 5 years ago

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?

thiagomaia971 commented 5 years ago

It's gonna be very easy to make a validation in a model with this implementation! @EisenbergEffect

bigopon commented 5 years ago

@iuribrindeiro that'd be awesome.

Here are some issues where you can get some more ideas to implement it (not listed in any order)

iuribrindeiro commented 5 years ago

Awesome,@bigopon! I'll open a PR soon for that :)

iuribrindeiro commented 5 years ago

Hey, @bigopon, can you help me create a PR? I should create a branch and then create a PR to develop?

glyad commented 3 years ago

@iuribrindeiro, nice idea! Just some proposals:

  1. 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")

  2. 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.