-
-
Notifications
You must be signed in to change notification settings - Fork 333
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
paper-input: external validations messages is unusable for server side validation #671
Comments
@panthony thank you for This works for me: import attr from 'ember-data/attr';
import Ember from 'ember';
import Model from 'ember-data/model';
const { computed: { mapBy } } = Ember;
export default Model.extend({
email: attr('string'),
emailErrors: mapBy('errors.email', 'message'),
}); {{form.input
label="Email"
value=user.email
errors=user.emailErrors
onChange=(action (mut user.email))
isTouched=user.emailErrors.length
}}
|
@mpugach Let me return the favor for your nice implementation of the workaround :) |
I just ran into this. Is this something that should just work when the errors attribute is updated? |
it just works for me, because my backend returns a correct errors object, which is understood by JSONAPISerializer I just need to extract the messages with |
That seems like an unnecessary step - my backend returns JSON-API errors as well, and is in turn set on an object (model.validations.attrs.[field].messages, in this case, because of ember-cp-validations). When that object updates the errors display of the field is not updated. I can verify this by inspecting the object before touching the field to see the error message. Once I focus/unfocus the field the error message is correctly displayed. |
do you have a public repo or can you localize it into one? |
I agree, this is a pretty big omission from Ember Paper. Not only do you have to make sure |
PRs are welcome ))) |
The last PR I opened was ignored for a month, not especially willing to contribute more |
We're all trying to give our best here. Are you referring to this: #693 |
Yes, sorry to be so bitter about it |
Hey, thanks for the discussion, I was having a hard time getting my JSON API validation errors to show. I came up with this hackish property to place in a model to construct the necessary arrays to pass to the input components:
Then I can set Probably there’s a way to avoid using If you have an idea of how you’d want to see this solved, @miguelcobain, I’m willing to try to address it. |
I'm in a situation where I can't validate some form inputs client-side, I have to submit the form and the server may reject it with a
422
and errors for invalid inputs.In this case I tried to pass those messages to the input using the
errors
property but I encountered the following issues:The input won't be displayed in error state until the user focus AND loose focus
The errors won't be cleared when the user modify the value, leaving the feeling to the user that he did not fix the issue
The suggested solution for the first issue was to pass the
isTouched
attribute to true manually.And I guess the solution for the second issue would be to have an external observer that reset the errors attribute when the value is updated.
But this is very cumbersome for a pattern that is pretty common I guess.
The text was updated successfully, but these errors were encountered: