Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

decorators for validations #523

Open
iuribrindeiro opened this issue May 8, 2019 · 5 comments
Open

decorators for validations #523

iuribrindeiro opened this issue May 8, 2019 · 5 comments

Comments

@iuribrindeiro
Copy link

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
Copy link

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

@bigopon
Copy link
Member

bigopon commented May 8, 2019

@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
Copy link
Author

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

@iuribrindeiro
Copy link
Author

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

@glyad
Copy link

glyad commented Oct 4, 2020

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants