validation icon indicating copy to clipboard operation
validation copied to clipboard

decorators for validations

Open iuribrindeiro opened this issue 6 years ago • 5 comments

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?

iuribrindeiro avatar May 08 '19 00:05 iuribrindeiro

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

thiagomaia971 avatar May 08 '19 12:05 thiagomaia971

@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

bigopon avatar May 08 '19 13:05 bigopon

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

iuribrindeiro avatar May 08 '19 13:05 iuribrindeiro

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

iuribrindeiro avatar May 12 '19 17:05 iuribrindeiro

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

glyad avatar Oct 04 '20 12:10 glyad