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

Alias validator #161

Merged
merged 6 commits into from
Apr 25, 2016
Merged

Alias validator #161

merged 6 commits into from
Apr 25, 2016

Conversation

offirgolan
Copy link
Collaborator

Creates an alias between a single attribute's validations to another.

 // Examples
 validator('alias', 'attribute')
 validator('alias', {
   alias: 'attribute'
 })

@blimmer Let me know what you think. I went kinda crazy and cleaned up some stuff.

The important files are:

  • addon/validations/factory.js
  • addon/validators/alias.js
  • tests/integration/validations/model-relationships-test.js

Resolves #160

assert.equal(user.get('validations.attrs.firstName.isValid'), false);
assert.equal(user.get('validations.attrs.lastName.isValid'), false);
assert.equal(user.get('validations.attrs.fullName.isValid'), false);
assert.deepEqual(user.get('validations.attrs.fullName.messages').sort(), ['firstName should be present', 'lastName should be present'].sort());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice - i think this is the right behavior vs. firstObject.

@blimmer
Copy link
Collaborator

blimmer commented Apr 17, 2016

This LGTM cc @gustaff-weldon

@offirgolan
Copy link
Collaborator Author

offirgolan commented Apr 17, 2016

I feel like there will be a use-case where you might not want to
include every error message in the aliased validation. What do you think of
adding a firstMessageOnly option or something like that?

@blimmer
Copy link
Collaborator

blimmer commented Apr 17, 2016

I think the option is reasonable, or just documentation around firstObject. It's a pretty common ember pattern to use to get the first object from an array.

@offirgolan
Copy link
Collaborator Author

@blimmer not sure I follow what you mean.

@blimmer
Copy link
Collaborator

blimmer commented Apr 21, 2016

Sorry, just reread my comment and it wasn't very clear. I was thinking that a firstMessageOnly will really just get the messages and then call .firstObject on the array. I think most ember folks know about it, but I think the option is a good idea for validations that you always want only one message. I could see people using that as a global validation option, too, so that plan sounds good to me!

@offirgolan offirgolan merged commit e238132 into master Apr 25, 2016
@offirgolan offirgolan deleted the alias-validator branch April 25, 2016 21:37
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

Successfully merging this pull request may close these issues.

None yet

2 participants