Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ember sample app with server-side validation handling

I'm looking for an Ember open-source or sample app, using Ember-data, that is relying on an API and that handles server-side validation.

I have a very hard time finding examples of a good, standard way to handle server-side validation with Ember and Ember-data.

like image 399
Robin Avatar asked Oct 03 '22 15:10

Robin


1 Answers

If your API returns validations errors with a 422, similar to:

{"errors":{"email":["can't be blank"]}}

then, the simplest way to let the user know something didn't validate properly, is to place the error message next to the appropriate control in your template:

{{view Ember.TextField id="email" placeholder="Email" valueBinding="email"}}<span class="alert-error">{{errors.email}}</span>

If you'd like to loop through the errors and maybe show them to the user in a different way (I like growl-like notifications in addition to inline messages), you can also grab them from the errors object on the model in the becameInvalid hook. The errors are also passed into the becameInvalid hook if you wanna grab them that way.

like image 60
yuяi Avatar answered Oct 13 '22 12:10

yuяi