ember.js - Count how many errors with Ember-Validations? -


i display count of validation errors user.

it implement message "you have x error(s) left" next submit button.

is there way ?

edit :

i using ember-validations 2.0.0-alpha.1 , ember 1.8.0 in context of controller (without ember data).

if try solution of sam:

this.get('errors.length') // result [], empty array 

the errors key holds object, not array. each key of object refers property on model , points array of error messages, can things this.get('errors.firstname.length').

to find total number of errors, you'd have through each of model's properties , sum number of errors each one.

http://emberjs.jsbin.com/luzesiyeqi/1/


edit:

the .length property of errors object returning empty array because of code: https://github.com/dockyard/ember-validations/blob/master/addon/errors.js. literally key access on errors object initialized empty array.


edit 2:

based on said in comments not wanting loop through properties, can in alternative fashion looking @ model's validators property. check out example:

numerrors: function () {   var errorcounts = this.get('model.validators').mapby('errors.length');   return errorcounts.reduce(function (a, b) { return + b }, 0); }.property('model.validators.@each.length') 

i've updated jsbin, too:

http://emberjs.jsbin.com/jucuxodaga/1/edit?html,js,output


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -