From cc5b673b77733ce73aadee61b3c70da05505c15d Mon Sep 17 00:00:00 2001 From: Jordan Harris Date: Wed, 29 Jun 2016 13:18:53 -0400 Subject: [PATCH 01/20] Fixed double sending of onInvalid action --- addon/components/paper-input.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/addon/components/paper-input.js b/addon/components/paper-input.js index 53c7da687..fff4c467a 100644 --- a/addon/components/paper-input.js +++ b/addon/components/paper-input.js @@ -200,9 +200,9 @@ export default BaseFocusable.extend(ColorMixin, FlexMixin, { notifyInvalid() { let isInvalid = this.get('isInvalid'); - if (this.get('lastIsInvalid') !== isInvalid) { - this.sendAction('onInvalid', this.get('isInvalid')); - this.set('lastIsInvalid', this.get('isInvalid')); + if (!!this.get('lastIsInvalid') !== !!isInvalid) { + this.sendAction('onInvalid', isInvalid); + this.set('lastIsInvalid', isInvalid); } }, From 5745ed65fc537718ad98e5f2038173ee7d2f7891 Mon Sep 17 00:00:00 2001 From: Jordan Harris Date: Wed, 29 Jun 2016 14:43:52 -0400 Subject: [PATCH 02/20] Better solution -- other didn't work properly when going from NULL to TRUE on isInvalid --- addon/components/paper-input.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/addon/components/paper-input.js b/addon/components/paper-input.js index fff4c467a..3eb766852 100644 --- a/addon/components/paper-input.js +++ b/addon/components/paper-input.js @@ -200,7 +200,10 @@ export default BaseFocusable.extend(ColorMixin, FlexMixin, { notifyInvalid() { let isInvalid = this.get('isInvalid'); - if (!!this.get('lastIsInvalid') !== !!isInvalid) { + let lastIsInvalid = this.get('lastIsInvalid'); + let isInvalidChanged = (lastIsInvalid !== isInvalid) + let isNotRedundant = !((lastIsInvalid === null && isInvalid) || (lastIsInvalid && isInvalid === null)); + if (isInvalidChanged && isNotRedundant) { this.sendAction('onInvalid', isInvalid); this.set('lastIsInvalid', isInvalid); } From 90cf27f39c05d0cad07a21eb89e8f968f5520542 Mon Sep 17 00:00:00 2001 From: Jordan Harris Date: Wed, 29 Jun 2016 14:54:06 -0400 Subject: [PATCH 03/20] Fixed semi-colon --- addon/components/paper-input.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addon/components/paper-input.js b/addon/components/paper-input.js index 3eb766852..c66ce479e 100644 --- a/addon/components/paper-input.js +++ b/addon/components/paper-input.js @@ -201,7 +201,7 @@ export default BaseFocusable.extend(ColorMixin, FlexMixin, { notifyInvalid() { let isInvalid = this.get('isInvalid'); let lastIsInvalid = this.get('lastIsInvalid'); - let isInvalidChanged = (lastIsInvalid !== isInvalid) + let isInvalidChanged = (lastIsInvalid !== isInvalid); let isNotRedundant = !((lastIsInvalid === null && isInvalid) || (lastIsInvalid && isInvalid === null)); if (isInvalidChanged && isNotRedundant) { this.sendAction('onInvalid', isInvalid); From 643f4583d99cd3037d5eaa6fd440cf3e3c9a1d9a Mon Sep 17 00:00:00 2001 From: Jordan Harris Date: Wed, 29 Jun 2016 18:15:18 -0400 Subject: [PATCH 04/20] Paper form complete --- addon/components/paper-form-container.js | 20 +++++++++++ addon/components/paper-form.js | 36 +++++++++++++++++++ app/components/paper-form-container.js | 3 ++ app/components/paper-form.js | 3 ++ .../components/paper-form-container.hbs | 1 + app/templates/components/paper-form.hbs | 1 + .../components/paper-form-container-test.js | 24 +++++++++++++ .../integration/components/paper-form-test.js | 24 +++++++++++++ 8 files changed, 112 insertions(+) create mode 100644 addon/components/paper-form-container.js create mode 100644 addon/components/paper-form.js create mode 100644 app/components/paper-form-container.js create mode 100644 app/components/paper-form.js create mode 100644 app/templates/components/paper-form-container.hbs create mode 100644 app/templates/components/paper-form.hbs create mode 100644 tests/integration/components/paper-form-container-test.js create mode 100644 tests/integration/components/paper-form-test.js diff --git a/addon/components/paper-form-container.js b/addon/components/paper-form-container.js new file mode 100644 index 000000000..c2af4eb2e --- /dev/null +++ b/addon/components/paper-form-container.js @@ -0,0 +1,20 @@ +import Ember from 'ember'; + +export default Ember.Component.extend({ + tagName: '', + attributeBindings: ['style'], + style: "width:100%", + customValidations: [], + hasValidation: Ember.computed('min', 'max', 'errorMessages', 'maxlength', 'required', 'customValidations', function() { + return this.get('min') || this.get('max') || this.get('errorMessages') || this.get('maxlength') || this.get('required') || this.get('customValidations'); + }), + didUpdateAttrs: function(params) { + if (params.oldAttrs.isTouched === params.newAttrs.isTouched) return; + this.set('touched', this.get('isTouched')); + }, + actions: { + callOnInvalid: function(status) { + this.get('onInvalid')(status); + } + } +}); diff --git a/addon/components/paper-form.js b/addon/components/paper-form.js new file mode 100644 index 000000000..83f361892 --- /dev/null +++ b/addon/components/paper-form.js @@ -0,0 +1,36 @@ +import Ember from 'ember'; + +export default Ember.Component.extend({ + tagName: '', + classNames: [], + attributeBindings: ['style'], + style: "width:100%", + numberOfInvalids: 0, + isValid: Ember.computed('numberOfInvalids', function() { + return this.get('numberOfInvalids') === 0 ? true : false; + }), + isInvalid: Ember.computed('isValid', function() { + return !this.get('isValid'); + }), + sendToParent: Ember.on('init', Ember.observer('isValid', function() { + if (!this.get('parentAction')) return; + this.get('parentAction')(this.get('isValid')); + })), + actions: { + onInvalid: function(status) { + if (status || status === null) { + this.set('numberOfInvalids', this.get('numberOfInvalids') + 1); + } else { + if (this.get('numberOfInvalids') === 0) return; + this.set('numberOfInvalids', this.get('numberOfInvalids') - 1); + } + }, + submit: function() { + if (this.get('parentSubmit')) { + this.get('parentSubmit')(); + } + this.set('isTouched', true); + this.set('isTouched', false); + } + } +}); \ No newline at end of file diff --git a/app/components/paper-form-container.js b/app/components/paper-form-container.js new file mode 100644 index 000000000..b59be62c6 --- /dev/null +++ b/app/components/paper-form-container.js @@ -0,0 +1,3 @@ +import PaperForm from 'ember-paper/components/paper-form-container'; + +export default PaperForm; \ No newline at end of file diff --git a/app/components/paper-form.js b/app/components/paper-form.js new file mode 100644 index 000000000..13578dea2 --- /dev/null +++ b/app/components/paper-form.js @@ -0,0 +1,3 @@ +import PaperForm from 'ember-paper/components/paper-form'; + +export default PaperForm; \ No newline at end of file diff --git a/app/templates/components/paper-form-container.hbs b/app/templates/components/paper-form-container.hbs new file mode 100644 index 000000000..9cd6f0144 --- /dev/null +++ b/app/templates/components/paper-form-container.hbs @@ -0,0 +1 @@ +{{paper-input type=type flex=flex label=label value=value onChange=onChange disabled=disabled min=min max=max errorMessages=errorMessages maxlength=maxlength required=required icon=icon hideAllMessages=hideAllMessages passThru=passThru onBlur=onBlur onFocus=onFocus onKeyDown=onKeyDown customValidations=customValidations class=class errors=errors isTouched=touched onInvalid=(if hasValidation (action 'callOnInvalid') null)}} diff --git a/app/templates/components/paper-form.hbs b/app/templates/components/paper-form.hbs new file mode 100644 index 000000000..3815af217 --- /dev/null +++ b/app/templates/components/paper-form.hbs @@ -0,0 +1 @@ +{{yield (hash validStatus=isValid isInvalid=isInvalid input=(component "paper-form-input-container" isTouched=isTouched onInvalid=(action 'onInvalid')) submit=(action 'submit'))}} diff --git a/tests/integration/components/paper-form-container-test.js b/tests/integration/components/paper-form-container-test.js new file mode 100644 index 000000000..6319e1571 --- /dev/null +++ b/tests/integration/components/paper-form-container-test.js @@ -0,0 +1,24 @@ +import { moduleForComponent, test } from 'ember-qunit'; +import hbs from 'htmlbars-inline-precompile'; + +moduleForComponent('paper-form-container', 'Integration | Component | paper form container', { + integration: true +}); + +test('it renders', function(assert) { + // Set any properties with this.set('myProperty', 'value'); + // Handle any actions with this.on('myAction', function(val) { ... }); + + this.render(hbs`{{paper-form-container}}`); + + assert.equal(this.$().text().trim(), ''); + + // Template block usage: + this.render(hbs` + {{#paper-form-container}} + template block text + {{/paper-form-container}} + `); + + assert.equal(this.$().text().trim(), 'template block text'); +}); diff --git a/tests/integration/components/paper-form-test.js b/tests/integration/components/paper-form-test.js new file mode 100644 index 000000000..609ec3d0f --- /dev/null +++ b/tests/integration/components/paper-form-test.js @@ -0,0 +1,24 @@ +import { moduleForComponent, test } from 'ember-qunit'; +import hbs from 'htmlbars-inline-precompile'; + +moduleForComponent('paper-form', 'Integration | Component | paper form', { + integration: true +}); + +test('it renders', function(assert) { + // Set any properties with this.set('myProperty', 'value'); + // Handle any actions with this.on('myAction', function(val) { ... }); + + this.render(hbs`{{paper-form}}`); + + assert.equal(this.$().text().trim(), ''); + + // Template block usage: + this.render(hbs` + {{#paper-form}} + template block text + {{/paper-form}} + `); + + assert.equal(this.$().text().trim(), 'template block text'); +}); From 1f5686228a68f3006ad63854584ab0b90eb4b498 Mon Sep 17 00:00:00 2001 From: Jordan Harris Date: Wed, 29 Jun 2016 18:22:19 -0400 Subject: [PATCH 05/20] Changed template to represent new container name --- app/templates/components/paper-form.hbs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/templates/components/paper-form.hbs b/app/templates/components/paper-form.hbs index 3815af217..6f5ded5c8 100644 --- a/app/templates/components/paper-form.hbs +++ b/app/templates/components/paper-form.hbs @@ -1 +1 @@ -{{yield (hash validStatus=isValid isInvalid=isInvalid input=(component "paper-form-input-container" isTouched=isTouched onInvalid=(action 'onInvalid')) submit=(action 'submit'))}} +{{yield (hash validStatus=isValid isInvalid=isInvalid input=(component "paper-form-container" isTouched=isTouched onInvalid=(action 'onInvalid')) submit=(action 'submit'))}} From d804a7839fec66a7599064a23b48a4eb81073137 Mon Sep 17 00:00:00 2001 From: Jordan Harris Date: Mon, 4 Jul 2016 12:41:31 -0400 Subject: [PATCH 06/20] Added ability for users who don't want to disable the submit button to display all errors on submit instead --- addon/components/paper-form-container.js | 2 +- addon/components/paper-form.js | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/addon/components/paper-form-container.js b/addon/components/paper-form-container.js index c2af4eb2e..d53b0c2d6 100644 --- a/addon/components/paper-form-container.js +++ b/addon/components/paper-form-container.js @@ -3,7 +3,7 @@ import Ember from 'ember'; export default Ember.Component.extend({ tagName: '', attributeBindings: ['style'], - style: "width:100%", + style: 'width:100%', customValidations: [], hasValidation: Ember.computed('min', 'max', 'errorMessages', 'maxlength', 'required', 'customValidations', function() { return this.get('min') || this.get('max') || this.get('errorMessages') || this.get('maxlength') || this.get('required') || this.get('customValidations'); diff --git a/addon/components/paper-form.js b/addon/components/paper-form.js index 83f361892..6e21869c7 100644 --- a/addon/components/paper-form.js +++ b/addon/components/paper-form.js @@ -4,7 +4,7 @@ export default Ember.Component.extend({ tagName: '', classNames: [], attributeBindings: ['style'], - style: "width:100%", + style: 'width:100%', numberOfInvalids: 0, isValid: Ember.computed('numberOfInvalids', function() { return this.get('numberOfInvalids') === 0 ? true : false; @@ -26,6 +26,11 @@ export default Ember.Component.extend({ } }, submit: function() { + if (this.get('isInvalid')) { + this.set('isTouched', false); + this.set('isTouched', true); + return; + } if (this.get('parentSubmit')) { this.get('parentSubmit')(); } From d3e5163a72980f85d9aeee2b78e4bca5ff321ecb Mon Sep 17 00:00:00 2001 From: Jordan Harris Date: Mon, 4 Jul 2016 13:33:21 -0400 Subject: [PATCH 07/20] Style fixes --- addon/components/paper-form-container.js | 12 ++++++++---- addon/components/paper-form.js | 17 +++++++++++------ 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/addon/components/paper-form-container.js b/addon/components/paper-form-container.js index d53b0c2d6..d45321062 100644 --- a/addon/components/paper-form-container.js +++ b/addon/components/paper-form-container.js @@ -1,19 +1,23 @@ import Ember from 'ember'; +const { Component } = Ember; -export default Ember.Component.extend({ +export default Component.extend({ tagName: '', attributeBindings: ['style'], style: 'width:100%', + onChange: null, customValidations: [], hasValidation: Ember.computed('min', 'max', 'errorMessages', 'maxlength', 'required', 'customValidations', function() { return this.get('min') || this.get('max') || this.get('errorMessages') || this.get('maxlength') || this.get('required') || this.get('customValidations'); }), - didUpdateAttrs: function(params) { - if (params.oldAttrs.isTouched === params.newAttrs.isTouched) return; + didUpdateAttrs(params) { + if (params.oldAttrs.isTouched === params.newAttrs.isTouched) { + return; + } this.set('touched', this.get('isTouched')); }, actions: { - callOnInvalid: function(status) { + callOnInvalid(status) { this.get('onInvalid')(status); } } diff --git a/addon/components/paper-form.js b/addon/components/paper-form.js index 6e21869c7..5fd80b24d 100644 --- a/addon/components/paper-form.js +++ b/addon/components/paper-form.js @@ -1,31 +1,36 @@ import Ember from 'ember'; +const { Component } = Ember; -export default Ember.Component.extend({ +export default Component.extend({ tagName: '', classNames: [], attributeBindings: ['style'], style: 'width:100%', numberOfInvalids: 0, isValid: Ember.computed('numberOfInvalids', function() { - return this.get('numberOfInvalids') === 0 ? true : false; + return this.get('numberOfInvalids') === 0; }), isInvalid: Ember.computed('isValid', function() { return !this.get('isValid'); }), sendToParent: Ember.on('init', Ember.observer('isValid', function() { - if (!this.get('parentAction')) return; + if (!this.get('parentAction')) { + return; + } this.get('parentAction')(this.get('isValid')); })), actions: { - onInvalid: function(status) { + onInvalid(status) { if (status || status === null) { this.set('numberOfInvalids', this.get('numberOfInvalids') + 1); } else { - if (this.get('numberOfInvalids') === 0) return; + if (this.get('numberOfInvalids') === 0) { + return; + } this.set('numberOfInvalids', this.get('numberOfInvalids') - 1); } }, - submit: function() { + submit() { if (this.get('isInvalid')) { this.set('isTouched', false); this.set('isTouched', true); From 68f497c022ff8fdeeef14eb78d5241f279a46d0c Mon Sep 17 00:00:00 2001 From: Jordan Harris Date: Tue, 5 Jul 2016 13:40:32 -0400 Subject: [PATCH 08/20] Fixed test errors --- addon/components/paper-form-container.js | 38 ++++----- addon/components/paper-form.js | 82 +++++++++---------- .../components/paper-form-container-test.js | 12 +-- 3 files changed, 66 insertions(+), 66 deletions(-) diff --git a/addon/components/paper-form-container.js b/addon/components/paper-form-container.js index d45321062..1ba9613d4 100644 --- a/addon/components/paper-form-container.js +++ b/addon/components/paper-form-container.js @@ -2,23 +2,23 @@ import Ember from 'ember'; const { Component } = Ember; export default Component.extend({ - tagName: '', - attributeBindings: ['style'], - style: 'width:100%', - onChange: null, - customValidations: [], - hasValidation: Ember.computed('min', 'max', 'errorMessages', 'maxlength', 'required', 'customValidations', function() { - return this.get('min') || this.get('max') || this.get('errorMessages') || this.get('maxlength') || this.get('required') || this.get('customValidations'); - }), - didUpdateAttrs(params) { - if (params.oldAttrs.isTouched === params.newAttrs.isTouched) { - return; - } - this.set('touched', this.get('isTouched')); - }, - actions: { - callOnInvalid(status) { - this.get('onInvalid')(status); - } - } + tagName: '', + attributeBindings: ['style'], + style: 'width:100%', + onChange: null, + customValidations: [], + hasValidation: Ember.computed('min', 'max', 'errorMessages', 'maxlength', 'required', 'customValidations', function() { + return this.get('min') || this.get('max') || this.get('errorMessages') || this.get('maxlength') || this.get('required') || this.get('customValidations'); + }), + didUpdateAttrs(params) { + if (params.oldAttrs.isTouched === params.newAttrs.isTouched) { + return; + } + this.set('touched', this.get('isTouched')); + }, + actions: { + callOnInvalid(status) { + this.get('onInvalid')(status); + } + } }); diff --git a/addon/components/paper-form.js b/addon/components/paper-form.js index 5fd80b24d..f04b03872 100644 --- a/addon/components/paper-form.js +++ b/addon/components/paper-form.js @@ -2,45 +2,45 @@ import Ember from 'ember'; const { Component } = Ember; export default Component.extend({ - tagName: '', - classNames: [], - attributeBindings: ['style'], - style: 'width:100%', - numberOfInvalids: 0, - isValid: Ember.computed('numberOfInvalids', function() { - return this.get('numberOfInvalids') === 0; - }), - isInvalid: Ember.computed('isValid', function() { - return !this.get('isValid'); - }), - sendToParent: Ember.on('init', Ember.observer('isValid', function() { - if (!this.get('parentAction')) { - return; - } - this.get('parentAction')(this.get('isValid')); - })), - actions: { - onInvalid(status) { - if (status || status === null) { - this.set('numberOfInvalids', this.get('numberOfInvalids') + 1); - } else { - if (this.get('numberOfInvalids') === 0) { - return; - } - this.set('numberOfInvalids', this.get('numberOfInvalids') - 1); - } - }, - submit() { - if (this.get('isInvalid')) { - this.set('isTouched', false); - this.set('isTouched', true); - return; - } - if (this.get('parentSubmit')) { - this.get('parentSubmit')(); - } - this.set('isTouched', true); - this.set('isTouched', false); - } - } + tagName: '', + classNames: [], + attributeBindings: ['style'], + style: 'width:100%', + numberOfInvalids: 0, + isValid: Ember.computed('numberOfInvalids', function() { + return this.get('numberOfInvalids') === 0; + }), + isInvalid: Ember.computed('isValid', function() { + return !this.get('isValid'); + }), + sendToParent: Ember.on('init', Ember.observer('isValid', function() { + if (!this.get('parentAction')) { + return; + } + this.get('parentAction')(this.get('isValid')); + })), + actions: { + onInvalid(status) { + if (status || status === null) { + this.set('numberOfInvalids', this.get('numberOfInvalids') + 1); + } else { + if (this.get('numberOfInvalids') === 0) { + return; + } + this.set('numberOfInvalids', this.get('numberOfInvalids') - 1); + } + }, + submit() { + if (this.get('isInvalid')) { + this.set('isTouched', false); + this.set('isTouched', true); + return; + } + if (this.get('parentSubmit')) { + this.get('parentSubmit')(); + } + this.set('isTouched', true); + this.set('isTouched', false); + } + } }); \ No newline at end of file diff --git a/tests/integration/components/paper-form-container-test.js b/tests/integration/components/paper-form-container-test.js index 6319e1571..5e9bca002 100644 --- a/tests/integration/components/paper-form-container-test.js +++ b/tests/integration/components/paper-form-container-test.js @@ -14,11 +14,11 @@ test('it renders', function(assert) { assert.equal(this.$().text().trim(), ''); // Template block usage: - this.render(hbs` - {{#paper-form-container}} - template block text - {{/paper-form-container}} - `); + // this.render(hbs` + // {{#paper-form-container}} + // template block text + // {{/paper-form-container}} + // `); - assert.equal(this.$().text().trim(), 'template block text'); + // assert.equal(this.$().text().trim(), 'template block text'); }); From bc3c3dbc4a85e751977b7b88e3c9f5583dc90697 Mon Sep 17 00:00:00 2001 From: Jordan Harris Date: Tue, 5 Jul 2016 13:49:00 -0400 Subject: [PATCH 09/20] Separate onInvalid changes and form changes. They are now different PRs --- addon/components/paper-input.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/addon/components/paper-input.js b/addon/components/paper-input.js index c66ce479e..53c7da687 100644 --- a/addon/components/paper-input.js +++ b/addon/components/paper-input.js @@ -200,12 +200,9 @@ export default BaseFocusable.extend(ColorMixin, FlexMixin, { notifyInvalid() { let isInvalid = this.get('isInvalid'); - let lastIsInvalid = this.get('lastIsInvalid'); - let isInvalidChanged = (lastIsInvalid !== isInvalid); - let isNotRedundant = !((lastIsInvalid === null && isInvalid) || (lastIsInvalid && isInvalid === null)); - if (isInvalidChanged && isNotRedundant) { - this.sendAction('onInvalid', isInvalid); - this.set('lastIsInvalid', isInvalid); + if (this.get('lastIsInvalid') !== isInvalid) { + this.sendAction('onInvalid', this.get('isInvalid')); + this.set('lastIsInvalid', this.get('isInvalid')); } }, From 9513e2eb283dba0afd747fe662a4195da83b88de Mon Sep 17 00:00:00 2001 From: Jordan Harris Date: Wed, 6 Jul 2016 09:57:49 -0400 Subject: [PATCH 10/20] Removed style attribute from tagless component --- addon/components/paper-form-container.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/addon/components/paper-form-container.js b/addon/components/paper-form-container.js index 1ba9613d4..b39b5e97e 100644 --- a/addon/components/paper-form-container.js +++ b/addon/components/paper-form-container.js @@ -3,8 +3,6 @@ const { Component } = Ember; export default Component.extend({ tagName: '', - attributeBindings: ['style'], - style: 'width:100%', onChange: null, customValidations: [], hasValidation: Ember.computed('min', 'max', 'errorMessages', 'maxlength', 'required', 'customValidations', function() { From 6cd51afceffad48d071838fe717be551809b82a2 Mon Sep 17 00:00:00 2001 From: Jordan Harris Date: Wed, 6 Jul 2016 11:00:41 -0400 Subject: [PATCH 11/20] Testing readonly again --- addon/components/paper-form.js | 4 ++-- app/templates/components/paper-form.hbs | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/addon/components/paper-form.js b/addon/components/paper-form.js index f04b03872..1585f26be 100644 --- a/addon/components/paper-form.js +++ b/addon/components/paper-form.js @@ -32,14 +32,14 @@ export default Component.extend({ }, submit() { if (this.get('isInvalid')) { - this.set('isTouched', false); + // this.set('isTouched', false); this.set('isTouched', true); return; } if (this.get('parentSubmit')) { this.get('parentSubmit')(); } - this.set('isTouched', true); + // this.set('isTouched', true); this.set('isTouched', false); } } diff --git a/app/templates/components/paper-form.hbs b/app/templates/components/paper-form.hbs index 6f5ded5c8..50ea4ec70 100644 --- a/app/templates/components/paper-form.hbs +++ b/app/templates/components/paper-form.hbs @@ -1 +1,4 @@ -{{yield (hash validStatus=isValid isInvalid=isInvalid input=(component "paper-form-container" isTouched=isTouched onInvalid=(action 'onInvalid')) submit=(action 'submit'))}} +{{!-- {{yield (hash validStatus=isValid isInvalid=isInvalid input=(component "paper-form-container" isTouched=isTouched onInvalid=(action 'onInvalid')) submit=(action 'submit'))}} --}} + +{{yield (hash validStatus=isValid isInvalid=isInvalid input=(component "paper-input" isTouched=(readonly isTouched) onInvalid=(action 'onInvalid')) submit=(action 'submit'))}} + From f9f99d68e689c1d5e453a919165fb28875a0f3ef Mon Sep 17 00:00:00 2001 From: Jordan Harris Date: Wed, 6 Jul 2016 11:26:54 -0400 Subject: [PATCH 12/20] Initiate isTouched in parent --- addon/components/paper-form.js | 1 + 1 file changed, 1 insertion(+) diff --git a/addon/components/paper-form.js b/addon/components/paper-form.js index 1585f26be..6753227a1 100644 --- a/addon/components/paper-form.js +++ b/addon/components/paper-form.js @@ -7,6 +7,7 @@ export default Component.extend({ attributeBindings: ['style'], style: 'width:100%', numberOfInvalids: 0, + isTouched: false, isValid: Ember.computed('numberOfInvalids', function() { return this.get('numberOfInvalids') === 0; }), From 5eccc4ba4f837ceebe2f90154992f12558712c32 Mon Sep 17 00:00:00 2001 From: Jordan Harris Date: Thu, 7 Jul 2016 20:34:49 -0400 Subject: [PATCH 13/20] Removed container -- implemented the container's purpose inside of the paper-input --- addon/components/paper-form-container.js | 22 ----------------- addon/components/paper-form.js | 9 ++----- addon/components/paper-input.js | 17 +++++++++++++ app/components/paper-form-container.js | 3 --- .../components/paper-form-container.hbs | 1 - app/templates/components/paper-form.hbs | 4 +--- .../components/paper-form-container-test.js | 24 ------------------- .../components/paper-input-test.js | 22 +++++++++++++++++ 8 files changed, 42 insertions(+), 60 deletions(-) delete mode 100644 addon/components/paper-form-container.js delete mode 100644 app/components/paper-form-container.js delete mode 100644 app/templates/components/paper-form-container.hbs delete mode 100644 tests/integration/components/paper-form-container-test.js diff --git a/addon/components/paper-form-container.js b/addon/components/paper-form-container.js deleted file mode 100644 index b39b5e97e..000000000 --- a/addon/components/paper-form-container.js +++ /dev/null @@ -1,22 +0,0 @@ -import Ember from 'ember'; -const { Component } = Ember; - -export default Component.extend({ - tagName: '', - onChange: null, - customValidations: [], - hasValidation: Ember.computed('min', 'max', 'errorMessages', 'maxlength', 'required', 'customValidations', function() { - return this.get('min') || this.get('max') || this.get('errorMessages') || this.get('maxlength') || this.get('required') || this.get('customValidations'); - }), - didUpdateAttrs(params) { - if (params.oldAttrs.isTouched === params.newAttrs.isTouched) { - return; - } - this.set('touched', this.get('isTouched')); - }, - actions: { - callOnInvalid(status) { - this.get('onInvalid')(status); - } - } -}); diff --git a/addon/components/paper-form.js b/addon/components/paper-form.js index 6753227a1..4c080639e 100644 --- a/addon/components/paper-form.js +++ b/addon/components/paper-form.js @@ -8,6 +8,7 @@ export default Component.extend({ style: 'width:100%', numberOfInvalids: 0, isTouched: false, + touchedTrigger: 0, isValid: Ember.computed('numberOfInvalids', function() { return this.get('numberOfInvalids') === 0; }), @@ -32,16 +33,10 @@ export default Component.extend({ } }, submit() { - if (this.get('isInvalid')) { - // this.set('isTouched', false); - this.set('isTouched', true); - return; - } if (this.get('parentSubmit')) { this.get('parentSubmit')(); } - // this.set('isTouched', true); - this.set('isTouched', false); + this.set('touchedTrigger', this.get('touchedTrigger') + 1); } } }); \ No newline at end of file diff --git a/addon/components/paper-input.js b/addon/components/paper-input.js index 25df26f19..699e0c30f 100644 --- a/addon/components/paper-input.js +++ b/addon/components/paper-input.js @@ -27,6 +27,11 @@ export default BaseFocusable.extend(ColorMixin, FlexMixin, { tabindex: null, hideAllMessages: false, isTouched: false, + // The below 2 properties exists so that paper-form can properly reset the isTouched property. Passing in isTouched with a read only helper + // doesn't work because when the component rerenders, it reinherits (wrongfully) the isTouched value of the parent on each rerender. + _isTouched: false, + touchedTrigger: 0, + previousTriggerValue: 0, lastIsInvalid: undefined, hasValue: computed('value', 'isNativeInvalid', function() { @@ -135,6 +140,18 @@ export default BaseFocusable.extend(ColorMixin, FlexMixin, { this.notifyInvalid(); }, + didUpdateAttrs(params) { + // This exists so that a form can properly reset the isTouched value upon successful submittal. Simply passing in a readonly version of the + // property does not work due to the fact that this component reinherits the isTouched value of the parent on every rerender. So here, + // we check to see that the facade property has actually changed before updating the real property. We have to use the increment properties + // to trigger the set in the case of the form resetting isTouched to false -- the parent value will have not changed, but we need to trigger + // isTouched to reset to false regardless + if (params.oldAttrs._isTouched !== params.newAttrs._isTouched || (this.get('touchedTrigger') > this.get('previousTriggerValue'))) { + this.set('previousTriggerValue', this.get('touchedTrigger')); + this.set('isTouched', this.get('_isTouched')); + } + }, + didInsertElement() { this._super(...arguments); if (this.get('textarea')) { diff --git a/app/components/paper-form-container.js b/app/components/paper-form-container.js deleted file mode 100644 index b59be62c6..000000000 --- a/app/components/paper-form-container.js +++ /dev/null @@ -1,3 +0,0 @@ -import PaperForm from 'ember-paper/components/paper-form-container'; - -export default PaperForm; \ No newline at end of file diff --git a/app/templates/components/paper-form-container.hbs b/app/templates/components/paper-form-container.hbs deleted file mode 100644 index 9cd6f0144..000000000 --- a/app/templates/components/paper-form-container.hbs +++ /dev/null @@ -1 +0,0 @@ -{{paper-input type=type flex=flex label=label value=value onChange=onChange disabled=disabled min=min max=max errorMessages=errorMessages maxlength=maxlength required=required icon=icon hideAllMessages=hideAllMessages passThru=passThru onBlur=onBlur onFocus=onFocus onKeyDown=onKeyDown customValidations=customValidations class=class errors=errors isTouched=touched onInvalid=(if hasValidation (action 'callOnInvalid') null)}} diff --git a/app/templates/components/paper-form.hbs b/app/templates/components/paper-form.hbs index 50ea4ec70..e7c48082f 100644 --- a/app/templates/components/paper-form.hbs +++ b/app/templates/components/paper-form.hbs @@ -1,4 +1,2 @@ -{{!-- {{yield (hash validStatus=isValid isInvalid=isInvalid input=(component "paper-form-container" isTouched=isTouched onInvalid=(action 'onInvalid')) submit=(action 'submit'))}} --}} - -{{yield (hash validStatus=isValid isInvalid=isInvalid input=(component "paper-input" isTouched=(readonly isTouched) onInvalid=(action 'onInvalid')) submit=(action 'submit'))}} +{{yield (hash validStatus=isValid isInvalid=isInvalid input=(component "paper-input" _isTouched=(readonly isTouched) onInvalid=(action 'onInvalid') touchedTrigger=touchedTrigger) submit=(action 'submit'))}} diff --git a/tests/integration/components/paper-form-container-test.js b/tests/integration/components/paper-form-container-test.js deleted file mode 100644 index 5e9bca002..000000000 --- a/tests/integration/components/paper-form-container-test.js +++ /dev/null @@ -1,24 +0,0 @@ -import { moduleForComponent, test } from 'ember-qunit'; -import hbs from 'htmlbars-inline-precompile'; - -moduleForComponent('paper-form-container', 'Integration | Component | paper form container', { - integration: true -}); - -test('it renders', function(assert) { - // Set any properties with this.set('myProperty', 'value'); - // Handle any actions with this.on('myAction', function(val) { ... }); - - this.render(hbs`{{paper-form-container}}`); - - assert.equal(this.$().text().trim(), ''); - - // Template block usage: - // this.render(hbs` - // {{#paper-form-container}} - // template block text - // {{/paper-form-container}} - // `); - - // assert.equal(this.$().text().trim(), 'template block text'); -}); diff --git a/tests/integration/components/paper-input-test.js b/tests/integration/components/paper-input-test.js index 401e72305..1d4e8c06e 100644 --- a/tests/integration/components/paper-input-test.js +++ b/tests/integration/components/paper-input-test.js @@ -460,4 +460,26 @@ test('errors only show after input is touched and input is invalid', function(as assert.equal(this.$('.paper-input-error').length, 1, 'render md-input-invalid class'); assert.equal(this.$('.md-input-invalid').length, 1, 'renders one error'); +}); + +test('isTouched updates properly when passed in from parent', function(assert) { + assert.expect(6); + + this.set('isTouched', false); + this.set('touchedIncrement', 0); + + this.render(hbs`{{paper-input value=value onChange=(action (mut value)) _isTouched=(readonly isTouched) touchedTrigger=touchedIncrement}}`); + + assert.equal(this.$('.ng-dirty').length, 0, 'has not been touched'); + this.$('input, textarea').trigger('blur'); + assert.equal(this.$('.ng-dirty').length, 1, 'has been touched'); + this.$('input, textarea').val('12345').trigger('input'); + assert.equal(this.$('.ng-dirty').length, 1, 'has been touched after input'); + this.$('input, textarea').trigger('blur'); + assert.equal(this.$('.ng-dirty').length, 1, 'has been touched after blur'); + this.set('touchedIncrement', this.get('touchedIncrement') + 1); + assert.equal(this.$('.ng-dirty').length, 0, 'has not been touched after parent value does not change but trigger does'); + this.set('isTouched', true); + assert.equal(this.$('.ng-dirty').length, 1, 'has been touched after parent value changes to true'); + }); \ No newline at end of file From 5eb24fef873c461c23f782842b79d838a996a21a Mon Sep 17 00:00:00 2001 From: Jordan Harris Date: Thu, 7 Jul 2016 20:37:44 -0400 Subject: [PATCH 14/20] Removed style from tagless component --- addon/components/paper-form.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/addon/components/paper-form.js b/addon/components/paper-form.js index 4c080639e..80fdd1952 100644 --- a/addon/components/paper-form.js +++ b/addon/components/paper-form.js @@ -3,19 +3,16 @@ const { Component } = Ember; export default Component.extend({ tagName: '', - classNames: [], - attributeBindings: ['style'], - style: 'width:100%', numberOfInvalids: 0, isTouched: false, touchedTrigger: 0, - isValid: Ember.computed('numberOfInvalids', function() { + isValid: computed('numberOfInvalids', function() { return this.get('numberOfInvalids') === 0; }), - isInvalid: Ember.computed('isValid', function() { + isInvalid: computed('isValid', function() { return !this.get('isValid'); }), - sendToParent: Ember.on('init', Ember.observer('isValid', function() { + sendToParent: on('init', observer('isValid', function() { if (!this.get('parentAction')) { return; } @@ -36,7 +33,7 @@ export default Component.extend({ if (this.get('parentSubmit')) { this.get('parentSubmit')(); } - this.set('touchedTrigger', this.get('touchedTrigger') + 1); + this.set('touchedTrigger', this.get('touchedTrigger') + 1) } } }); \ No newline at end of file From 21d8648acce2d5e646284af87751ab9d72d41d3b Mon Sep 17 00:00:00 2001 From: Jordan Harris Date: Thu, 7 Jul 2016 20:46:46 -0400 Subject: [PATCH 15/20] Added destructuring --- addon/components/paper-form.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addon/components/paper-form.js b/addon/components/paper-form.js index 80fdd1952..19cc12c51 100644 --- a/addon/components/paper-form.js +++ b/addon/components/paper-form.js @@ -1,5 +1,5 @@ import Ember from 'ember'; -const { Component } = Ember; +const { Component, computed, on, observer } = Ember; export default Component.extend({ tagName: '', From 88c9033a894928a6ad142bd4d874ee42eabda857 Mon Sep 17 00:00:00 2001 From: Jordan Harris Date: Thu, 7 Jul 2016 20:49:26 -0400 Subject: [PATCH 16/20] Fixed semicolon issue --- addon/components/paper-form.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addon/components/paper-form.js b/addon/components/paper-form.js index 19cc12c51..892ba2ba1 100644 --- a/addon/components/paper-form.js +++ b/addon/components/paper-form.js @@ -33,7 +33,7 @@ export default Component.extend({ if (this.get('parentSubmit')) { this.get('parentSubmit')(); } - this.set('touchedTrigger', this.get('touchedTrigger') + 1) + this.set('touchedTrigger', this.get('touchedTrigger') + 1); } } }); \ No newline at end of file From 011b9f07bf104daf1f5036cbac61738e16ee79f3 Mon Sep 17 00:00:00 2001 From: Jordan Harris Date: Fri, 8 Jul 2016 16:58:32 -0400 Subject: [PATCH 17/20] Revised paper-form now uses mixins as opposed to a hacky solution (_isTouched to incrementCounter) --- addon/components/paper-form.js | 25 ++++++------------- addon/components/paper-input.js | 20 ++------------- addon/mixins/child-mixin.js | 19 ++++++++++++++ addon/mixins/parent-mixin.js | 16 ++++++++++++ app/templates/components/paper-form.hbs | 2 +- .../components/paper-input-test.js | 22 ---------------- tests/unit/mixins/child-mixin-test.js | 12 +++++++++ tests/unit/mixins/parent-mixin-test.js | 12 +++++++++ 8 files changed, 69 insertions(+), 59 deletions(-) create mode 100644 addon/mixins/child-mixin.js create mode 100644 addon/mixins/parent-mixin.js create mode 100644 tests/unit/mixins/child-mixin-test.js create mode 100644 tests/unit/mixins/parent-mixin-test.js diff --git a/addon/components/paper-form.js b/addon/components/paper-form.js index 892ba2ba1..994db901d 100644 --- a/addon/components/paper-form.js +++ b/addon/components/paper-form.js @@ -1,13 +1,12 @@ import Ember from 'ember'; +import ParentMixin from 'ember-paper/mixins/parent-mixin'; + const { Component, computed, on, observer } = Ember; -export default Component.extend({ +export default Component.extend(ParentMixin, { tagName: '', - numberOfInvalids: 0, - isTouched: false, - touchedTrigger: 0, - isValid: computed('numberOfInvalids', function() { - return this.get('numberOfInvalids') === 0; + isValid: computed('childComponents.@each.isInvalid', function() { + return !this.get('childComponents').isAny('isInvalid'); }), isInvalid: computed('isValid', function() { return !this.get('isValid'); @@ -19,21 +18,11 @@ export default Component.extend({ this.get('parentAction')(this.get('isValid')); })), actions: { - onInvalid(status) { - if (status || status === null) { - this.set('numberOfInvalids', this.get('numberOfInvalids') + 1); - } else { - if (this.get('numberOfInvalids') === 0) { - return; - } - this.set('numberOfInvalids', this.get('numberOfInvalids') - 1); - } - }, submit() { if (this.get('parentSubmit')) { this.get('parentSubmit')(); } - this.set('touchedTrigger', this.get('touchedTrigger') + 1); + this.get('childComponents').setEach('isTouched', false); } } -}); \ No newline at end of file +}); diff --git a/addon/components/paper-input.js b/addon/components/paper-input.js index 699e0c30f..032dd3d2a 100644 --- a/addon/components/paper-input.js +++ b/addon/components/paper-input.js @@ -2,6 +2,7 @@ import Ember from 'ember'; import BaseFocusable from './base-focusable'; import ColorMixin from 'ember-paper/mixins/color-mixin'; import FlexMixin from 'ember-paper/mixins/flex-mixin'; +import ChildMixin from 'ember-paper/mixins/child-mixin'; import requiredValidator from 'ember-paper/validators/required'; import minValidator from 'ember-paper/validators/min'; @@ -11,7 +12,7 @@ import maxlengthValidator from 'ember-paper/validators/maxlength'; const { $, computed, isArray, isEmpty, Logger, A, run, assert, get } = Ember; -export default BaseFocusable.extend(ColorMixin, FlexMixin, { +export default BaseFocusable.extend(ColorMixin, FlexMixin, ChildMixin, { tagName: 'md-input-container', classNames: ['md-default-theme'], classNameBindings: [ @@ -27,11 +28,6 @@ export default BaseFocusable.extend(ColorMixin, FlexMixin, { tabindex: null, hideAllMessages: false, isTouched: false, - // The below 2 properties exists so that paper-form can properly reset the isTouched property. Passing in isTouched with a read only helper - // doesn't work because when the component rerenders, it reinherits (wrongfully) the isTouched value of the parent on each rerender. - _isTouched: false, - touchedTrigger: 0, - previousTriggerValue: 0, lastIsInvalid: undefined, hasValue: computed('value', 'isNativeInvalid', function() { @@ -140,18 +136,6 @@ export default BaseFocusable.extend(ColorMixin, FlexMixin, { this.notifyInvalid(); }, - didUpdateAttrs(params) { - // This exists so that a form can properly reset the isTouched value upon successful submittal. Simply passing in a readonly version of the - // property does not work due to the fact that this component reinherits the isTouched value of the parent on every rerender. So here, - // we check to see that the facade property has actually changed before updating the real property. We have to use the increment properties - // to trigger the set in the case of the form resetting isTouched to false -- the parent value will have not changed, but we need to trigger - // isTouched to reset to false regardless - if (params.oldAttrs._isTouched !== params.newAttrs._isTouched || (this.get('touchedTrigger') > this.get('previousTriggerValue'))) { - this.set('previousTriggerValue', this.get('touchedTrigger')); - this.set('isTouched', this.get('_isTouched')); - } - }, - didInsertElement() { this._super(...arguments); if (this.get('textarea')) { diff --git a/addon/mixins/child-mixin.js b/addon/mixins/child-mixin.js new file mode 100644 index 000000000..5a519e607 --- /dev/null +++ b/addon/mixins/child-mixin.js @@ -0,0 +1,19 @@ +import Ember from 'ember'; +const { Mixin } = Ember; + +export default Mixin.create({ + asdfgh: 'lel', + init() { + this._super(...arguments); + if (this.get('parentComponent')) { + this.get('parentComponent').register(this); + } + }, + + willDestroyElement() { + this._super(...arguments); + if (this.get('parentComponent')) { + this.get('parentComponent').unregister(this); + } + } +}); \ No newline at end of file diff --git a/addon/mixins/parent-mixin.js b/addon/mixins/parent-mixin.js new file mode 100644 index 000000000..715f7af1a --- /dev/null +++ b/addon/mixins/parent-mixin.js @@ -0,0 +1,16 @@ +import Ember from 'ember'; +const { Mixin, computed, A } = Ember; + +export default Mixin.create({ + childComponents: computed(function() { + return A(); + }), + + register(child) { + this.get('childComponents').pushObject(child); + }, + + unregister(child) { + this.get('childComponents').removeObject(child); + } +}); \ No newline at end of file diff --git a/app/templates/components/paper-form.hbs b/app/templates/components/paper-form.hbs index e7c48082f..77a7590ec 100644 --- a/app/templates/components/paper-form.hbs +++ b/app/templates/components/paper-form.hbs @@ -1,2 +1,2 @@ -{{yield (hash validStatus=isValid isInvalid=isInvalid input=(component "paper-input" _isTouched=(readonly isTouched) onInvalid=(action 'onInvalid') touchedTrigger=touchedTrigger) submit=(action 'submit'))}} +{{yield (hash validStatus=isValid isInvalid=isInvalid input=(component "paper-input" parentComponent=this) submit=(action 'submit'))}} diff --git a/tests/integration/components/paper-input-test.js b/tests/integration/components/paper-input-test.js index 1d4e8c06e..b621bae45 100644 --- a/tests/integration/components/paper-input-test.js +++ b/tests/integration/components/paper-input-test.js @@ -461,25 +461,3 @@ test('errors only show after input is touched and input is invalid', function(as assert.equal(this.$('.md-input-invalid').length, 1, 'renders one error'); }); - -test('isTouched updates properly when passed in from parent', function(assert) { - assert.expect(6); - - this.set('isTouched', false); - this.set('touchedIncrement', 0); - - this.render(hbs`{{paper-input value=value onChange=(action (mut value)) _isTouched=(readonly isTouched) touchedTrigger=touchedIncrement}}`); - - assert.equal(this.$('.ng-dirty').length, 0, 'has not been touched'); - this.$('input, textarea').trigger('blur'); - assert.equal(this.$('.ng-dirty').length, 1, 'has been touched'); - this.$('input, textarea').val('12345').trigger('input'); - assert.equal(this.$('.ng-dirty').length, 1, 'has been touched after input'); - this.$('input, textarea').trigger('blur'); - assert.equal(this.$('.ng-dirty').length, 1, 'has been touched after blur'); - this.set('touchedIncrement', this.get('touchedIncrement') + 1); - assert.equal(this.$('.ng-dirty').length, 0, 'has not been touched after parent value does not change but trigger does'); - this.set('isTouched', true); - assert.equal(this.$('.ng-dirty').length, 1, 'has been touched after parent value changes to true'); - -}); \ No newline at end of file diff --git a/tests/unit/mixins/child-mixin-test.js b/tests/unit/mixins/child-mixin-test.js new file mode 100644 index 000000000..d7f1dd9d6 --- /dev/null +++ b/tests/unit/mixins/child-mixin-test.js @@ -0,0 +1,12 @@ +import Ember from 'ember'; +import ChildMixinMixin from 'ember-paper/mixins/child-mixin'; +import { module, test } from 'qunit'; + +module('Unit | Mixin | child mixin'); + +// Replace this with your real tests. +test('it works', function(assert) { + let ChildMixinObject = Ember.Object.extend(ChildMixinMixin); + let subject = ChildMixinObject.create(); + assert.ok(subject); +}); diff --git a/tests/unit/mixins/parent-mixin-test.js b/tests/unit/mixins/parent-mixin-test.js new file mode 100644 index 000000000..08b3ff255 --- /dev/null +++ b/tests/unit/mixins/parent-mixin-test.js @@ -0,0 +1,12 @@ +import Ember from 'ember'; +import ParentMixinMixin from 'ember-paper/mixins/parent-mixin'; +import { module, test } from 'qunit'; + +module('Unit | Mixin | parent mixin'); + +// Replace this with your real tests. +test('it works', function(assert) { + let ParentMixinObject = Ember.Object.extend(ParentMixinMixin); + let subject = ParentMixinObject.create(); + assert.ok(subject); +}); From a7bb8bde481294f075a10dd976c9ee70d586174c Mon Sep 17 00:00:00 2001 From: Jordan Harris Date: Fri, 8 Jul 2016 17:04:18 -0400 Subject: [PATCH 18/20] Fixes --- addon/components/paper-form.js | 8 ++++---- addon/mixins/child-mixin.js | 1 - 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/addon/components/paper-form.js b/addon/components/paper-form.js index 994db901d..69c613193 100644 --- a/addon/components/paper-form.js +++ b/addon/components/paper-form.js @@ -5,11 +5,11 @@ const { Component, computed, on, observer } = Ember; export default Component.extend(ParentMixin, { tagName: '', - isValid: computed('childComponents.@each.isInvalid', function() { - return !this.get('childComponents').isAny('isInvalid'); + isValid: computed.not('childComponents.@each.isInvalid', function() { + return this.get('childComponents').isAny('isInvalid'); }), - isInvalid: computed('isValid', function() { - return !this.get('isValid'); + isInvalid: computed.not('isValid', function() { + return this.get('isValid'); }), sendToParent: on('init', observer('isValid', function() { if (!this.get('parentAction')) { diff --git a/addon/mixins/child-mixin.js b/addon/mixins/child-mixin.js index 5a519e607..c0d88dfa5 100644 --- a/addon/mixins/child-mixin.js +++ b/addon/mixins/child-mixin.js @@ -2,7 +2,6 @@ import Ember from 'ember'; const { Mixin } = Ember; export default Mixin.create({ - asdfgh: 'lel', init() { this._super(...arguments); if (this.get('parentComponent')) { From f09a160740c4eaa9a37c36802e017413dcdd9b4d Mon Sep 17 00:00:00 2001 From: Jordan Harris Date: Fri, 8 Jul 2016 19:54:08 -0400 Subject: [PATCH 19/20] Added .not --- addon/components/paper-form.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/addon/components/paper-form.js b/addon/components/paper-form.js index 69c613193..72f6e6213 100644 --- a/addon/components/paper-form.js +++ b/addon/components/paper-form.js @@ -5,12 +5,10 @@ const { Component, computed, on, observer } = Ember; export default Component.extend(ParentMixin, { tagName: '', - isValid: computed.not('childComponents.@each.isInvalid', function() { - return this.get('childComponents').isAny('isInvalid'); - }), - isInvalid: computed.not('isValid', function() { - return this.get('isValid'); + isValid: computed('childComponents.@each.isInvalid', function() { + return !this.get('childComponents').isAny('isInvalid'); }), + isInvalid: computed.not('isValid'), sendToParent: on('init', observer('isValid', function() { if (!this.get('parentAction')) { return; From a9e236c5b5b2235881d92707a505be8359490707 Mon Sep 17 00:00:00 2001 From: Jordan Harris Date: Sat, 9 Jul 2016 00:38:24 -0400 Subject: [PATCH 20/20] Simplified form --- addon/components/paper-form.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/addon/components/paper-form.js b/addon/components/paper-form.js index 72f6e6213..d671ef519 100644 --- a/addon/components/paper-form.js +++ b/addon/components/paper-form.js @@ -5,10 +5,10 @@ const { Component, computed, on, observer } = Ember; export default Component.extend(ParentMixin, { tagName: '', - isValid: computed('childComponents.@each.isInvalid', function() { - return !this.get('childComponents').isAny('isInvalid'); + isValid: computed.not('isInvalid'), + isInvalid: computed('childComponents.@each.isInvalid', function() { + return this.get('childComponents').isAny('isInvalid'); }), - isInvalid: computed.not('isValid'), sendToParent: on('init', observer('isValid', function() { if (!this.get('parentAction')) { return;