diff --git a/addon/mixins/controllers/saving.js b/addon/mixins/controllers/saving.js index fbe0723..85c43f8 100644 --- a/addon/mixins/controllers/saving.js +++ b/addon/mixins/controllers/saving.js @@ -31,7 +31,7 @@ export default Ember.Mixin.create( validateAndSave: function() { var _this = this; - var runCustomValidations = _this.runCustomValidations; + var customValidationsPromise; var resolve = function() { Ember.assert( @@ -48,10 +48,16 @@ export default Ember.Mixin.create( /* If there is a custom validations method, resolve it */ - if (runCustomValidations && !runCustomValidations.then) { - Ember.assert('runCustomValidations() must return a promise (e.g. return new Ember.RSVP.Promise()).'); - } else if (runCustomValidations) { - runCustomValidations().then(resolve, reject); + if (this.runCustomValidations) { + customValidationsPromise = this.runCustomValidations(); + + if (!customValidationsPromise.then) { + Ember.assert( + 'runCustomValidations() must return a promise (e.g. return new Ember.RSVP.Promise(...)).' + ); + } + + customValidationsPromise.then(resolve, reject); } else { /* Else save with normal ember-validations checks */ diff --git a/addon/mixins/views/submitting.js b/addon/mixins/views/submitting.js index a63bbc4..f953a2a 100644 --- a/addon/mixins/views/submitting.js +++ b/addon/mixins/views/submitting.js @@ -65,7 +65,7 @@ export default Ember.Mixin.create({ var controller = this.get('controller'); var methodName = type + 'Handler'; var handler = this[methodName]; - var controllerMethod; + var controllerMethod, handlerPromise; /* If event is submit, controller method is renamed */ @@ -88,9 +88,15 @@ export default Ember.Mixin.create({ Ember.typeOf(handler) === 'function' ); - /* TODO - need a way to assert whether handler is a promise */ + handlerPromise = handler(); - handler().then(function() { + if (!handlerPromise.then) { + Ember.assert( + 'handler() must return a promise (e.g. return new Ember.RSVP.Promise(...))' + ); + } + + handlerPromise.then(function() { controller[type](); }); diff --git a/package.json b/package.json index 2518e1a..36db39c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ember-easy-form-extensions", - "version": "0.2.7", + "version": "0.2.8", "description": "Extends Ember EasyForm into the view and controller layers of your Ember CLI app to provide easy event and action handling using mixins and components.", "directories": { "doc": "doc",