From 89283661764fd9edfb7db114bdb7d0597e3abe64 Mon Sep 17 00:00:00 2001 From: Kory Tegman Date: Wed, 17 Dec 2014 14:26:08 -0800 Subject: [PATCH] add show errors on submit --- addon/form.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/addon/form.js b/addon/form.js index d6a1c81..ca14e04 100644 --- a/addon/form.js +++ b/addon/form.js @@ -46,11 +46,12 @@ export default Em.Component.extend({ /* Form submit - + Optionally execute model validations and perform a form submission. */ submit: function(e) { var promise; + var self = this; if (e) { e.preventDefault(); } @@ -64,7 +65,21 @@ export default Em.Component.extend({ return _this.get('targetObject').send(_this.get('action')); } }; + })(this)).catch((function(_this) { + // if the form don't valdiate. + // show errors on all fields. + self.showErrors(_this); })(this)); } } + // show errors on all child fields. + showErrors: function (view) { + var self = this; + jQuery.each(view._childViews, function (key, validation) { + validation.set('canShowErrors', true); + if (validation._childViews) { + self.showErrors(validation); + } + }); + } }); \ No newline at end of file