From 2e742ea903d49bac679aafe65210584b1bf38c60 Mon Sep 17 00:00:00 2001 From: jelhan Date: Sun, 26 Oct 2014 18:19:07 +0100 Subject: [PATCH] validate only on focusOut or submit --- app/controllers/create/index.js | 6 ++++++ app/controllers/create/meta.js | 6 ++++++ app/controllers/create/options-datetime.js | 6 ++++++ app/controllers/create/options.js | 6 ++++++ app/controllers/create/settings.js | 6 ++++++ app/controllers/poll.js | 6 ++++++ app/initializers/ember-easyForm.js | 11 +++-------- 7 files changed, 39 insertions(+), 8 deletions(-) diff --git a/app/controllers/create/index.js b/app/controllers/create/index.js index bc7aa7c..6c92f87 100644 --- a/app/controllers/create/index.js +++ b/app/controllers/create/index.js @@ -8,6 +8,12 @@ export default Ember.ObjectController.extend(Ember.Validations.Mixin, { submit: function(){ this.validate(); + $.each(Ember.View.views, function(id, view) { + if(view.isEasyForm) { + view.focusOut(); + } + }); + if (this.get('isValid')) { this.send('save'); } diff --git a/app/controllers/create/meta.js b/app/controllers/create/meta.js index bbe1877..ea5a8cd 100644 --- a/app/controllers/create/meta.js +++ b/app/controllers/create/meta.js @@ -8,6 +8,12 @@ export default Ember.ObjectController.extend(Ember.Validations.Mixin, { submit: function(){ this.validate(); + $.each(Ember.View.views, function(id, view) { + if(view.isEasyForm) { + view.focusOut(); + } + }); + if (this.get('isValid')) { this.send('save'); } diff --git a/app/controllers/create/options-datetime.js b/app/controllers/create/options-datetime.js index b748389..54fb54f 100644 --- a/app/controllers/create/options-datetime.js +++ b/app/controllers/create/options-datetime.js @@ -88,6 +88,12 @@ export default Ember.ObjectController.extend(Ember.Validations.Mixin, { submit: function(){ this.validate(); + $.each(Ember.View.views, function(id, view) { + if(view.isEasyForm) { + view.focusOut(); + } + }); + if (this.get('isValid')) { // tricker save action this.send('save'); diff --git a/app/controllers/create/options.js b/app/controllers/create/options.js index d0417b7..9ef209d 100644 --- a/app/controllers/create/options.js +++ b/app/controllers/create/options.js @@ -36,6 +36,12 @@ export default Ember.ObjectController.extend(Ember.Validations.Mixin, { submit: function() { this.validate(); + $.each(Ember.View.views, function(id, view) { + if(view.isEasyForm) { + view.focusOut(); + } + }); + if (this.get('isValid')) { // tricker save action this.send('save'); diff --git a/app/controllers/create/settings.js b/app/controllers/create/settings.js index 2835afb..5a7fa8f 100644 --- a/app/controllers/create/settings.js +++ b/app/controllers/create/settings.js @@ -20,6 +20,12 @@ export default Ember.ObjectController.extend(Ember.Validations.Mixin, { submit: function() { this.validate(); + $.each(Ember.View.views, function(id, view) { + if(view.isEasyForm) { + view.focusOut(); + } + }); + if (this.get('isValid')) { // tricker save action this.send('save'); diff --git a/app/controllers/poll.js b/app/controllers/poll.js index bd917dc..d9fa55e 100644 --- a/app/controllers/poll.js +++ b/app/controllers/poll.js @@ -50,6 +50,12 @@ export default Ember.ObjectController.extend(Ember.Validations.Mixin, { submitNewUser: function() { this.validate(); + + $.each(Ember.View.views, function(id, view) { + if(view.isEasyForm) { + view.focusOut(); + } + }); if (this.get('isValid')) { // tricker save action diff --git a/app/initializers/ember-easyForm.js b/app/initializers/ember-easyForm.js index dd3c581..c889fb4 100644 --- a/app/initializers/ember-easyForm.js +++ b/app/initializers/ember-easyForm.js @@ -7,14 +7,7 @@ export default { initialize: function() { Ember.EasyForm.Input.reopen({ - errorsChanged: function() { - this.set('hasFocusedOut', true); - this.showValidationError(); - }, classNameBindings: ['wrapperConfig.inputClass', 'wrapperErrorClass'], - didInsertElement: function() { - this.addObserver('context.errors.' + this.property + '.@each', this, 'errorsChanged'); - }, isCheckbox: function() { if (this.get('inputOptionsValues.as') === 'checkbox') { return true; @@ -30,7 +23,9 @@ export default { else { return ''; } - }.property('inputOptionsValues') + }.property('inputOptionsValues'), + + isEasyForm: true }); Ember.EasyForm.Error.reopen({