-
Notifications
You must be signed in to change notification settings - Fork 16
support multiple validation errors #29
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
Conversation
does this seem legit to you? |
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.
ps. I've tried a unit test, but failed... :-/
I guess you meant a component integration test? Could you share what you have tried? I can not recall when I have seen validation
to be an array of validation messages. It would be helpful if you can provide an example for that one.
addon/components/bs-form/element.js
Outdated
let error = get(this, `model.error.${this.property}.validation`); | ||
return error ? [error] : []; | ||
let errors = get(this, `model.error.${this.property}.validation`); | ||
return errors ? errors : []; |
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.
If I understand the documentation of validated-changeset correctly, model.error.${this.property}.validation
could be either a string or an array: https://github.com/validated-changeset/validated-changeset/#error
Ember Bootstrap expects errors
property of FormElement to be an array of validation messages: https://www.ember-bootstrap.com/api/classes/Components.FormElement.html#property_errors
Of course model.error.[this.property]
could also be undefined if the property is valid. So it seems like we need to handle three cases here:
model.error.${this.property}.validation
isundefined
-> return empty arraymodel.error.${this.property}.validation
is a string -> wrap that string into an array and return that onemodel.error.${this.property}.validation
is an array -> return that array
Can you please update the code accordingly? Some in-source comments about the different states may also be helpful for future readers.
will do... you are correct; arrays are returned when multiple (an array of) validators have been defined. |
as for testing. I think i need to do this
to create a unit test for the component. However it (empty) fails to run with 'TypeError: Cannot convert undefined or null to object' |
I think unit tests are not supported for |
hmmm... ok. how do we test undefined then. Simply no rendered message? |
Yes. |
there added a test for each case |
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 looks great. Thanks a lot.
If you have some time left an additional test case that multiple validation errors are actually shown if showMultipleErrors
argument of <BsForm:: Element>
is true
would be great. But I totally understand if you don't have any more bandwidth to work on this topic. Would merge as-is in that case.
Nope, wanted to but forgot in 34 degrees. Will do tomorrow
… On 12 Aug 2020, at 19:31, Jeldrik Hanschke ***@***.***> wrote:
@jelhan approved this pull request.
This looks great. Thanks a lot.
If you have some time left an additional test case that multiple validation errors are actually shown if showMultipleErrors argument of <BsForm:: Element> is true would be great. But I totally understand if you don't have any more bandwidth to work on this topic. Would merge as-is in that case.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
will you do a release or are you waiting on other stuff? |
Will try to do a release later today. |
Released v3.1.2 containing this fix just right now. |
Prevents
get errors()
to return an array-in-array with messages.This results in all validation messages to be rendered even when
showMultipleErrors
is false...ps. I've tried a unit test, but failed... :-/