-
-
Notifications
You must be signed in to change notification settings - Fork 171
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
Add enumerable list of all error objects #59
Add enumerable list of all error objects #59
Conversation
I think this will need some tests. Also, can you tweak the docs to indicate what the contents of .errors will be? |
Good idea - caught a mistake (although I have a sneaking suspicion you knew that already 😉 ) Let me know if you'd like me to squash, or if I missed something in my test coverage. |
I like this idea but I don't believe this is the best approach. If you look at how the addon is structured, all validation objects share the same model. Meaning that the global props, validation-result, and validation-result-collection all have (messages, invalid, valid, etc.). All this is currently doing is putting |
@offirgolan glad to hear you like the idea. So adding an I could introduce a new concept (an "Error object" for lack of a better name) that is essentially just the message & attribute name, and attach those at each level. Is that what you had in mind? |
Since all validations are composed of validation {
attribute: get(this, 'attribute'),
message: message
} Or like you said, we can introduce a new concept export default Ember.Object.extend({
attribute: null,
message: null
}) And just create these. I kind of prefer the latter since it can scale better? From the global props perspective, it can be identical to how the global messages property is computed. @rwjblue thoughts? |
Actually now that I think of it, the initial error object creation should happen on the |
@offirgolan alrighty, updated. Let me know how that looks. |
|
||
attribute: null, | ||
message: null | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you remove these empty lines (before and after the props)
This looks great! If you can just fix that one comment and rebase this to a single commit, I will merge this 😺 |
} | ||
}), | ||
|
||
errors: computed('error', function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isnt needed here. A result will only have a single error unless the _validations object get replaced by a validation-result object (only in belongs-to and has-many). Thats why the messages CP exists here but no actually messages prop.
c31f9aa
to
23eb2b9
Compare
@offirgolan address both comments and rebased! |
Beautiful! 💯 thank you sir! |
Add enumerable list of all error objects
🍻 |
Currently,
validations.messages
exposes a flattened array of all error messages present. It would be useful (for a variety of reasons) to have access to both the message as well as the attribute name it corresponds to.This PR adds
validations.errors
following the same pattern asvalidations.messages
(it also addsvalidations.error
).(docs included)