Skip to content

Commit

Permalink
make paper-form work with non contextual paper-inputs
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelcobain committed Jul 11, 2016
1 parent 6d65462 commit 35d457f
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
14 changes: 12 additions & 2 deletions addon/mixins/child-mixin.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
import Ember from 'ember';
const { Mixin } = Ember;
import ParentMixin from 'ember-paper/mixins/parent-mixin';
const { Mixin, computed } = Ember;

export default Mixin.create({

// override to look for a specific parent class
parentClass: ParentMixin,

// this will typically be overriden when yielding a contextual component
parentComponent: computed(function() {
return this.nearestOfType(this.get('parentClass'));
}),

init() {
this._super(...arguments);
if (this.get('parentComponent')) {
Expand All @@ -15,4 +25,4 @@ export default Mixin.create({
this.get('parentComponent').unregister(this);
}
}
});
});
35 changes: 34 additions & 1 deletion tests/integration/components/paper-form-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,37 @@ test('form is reset after submit action is invoked', function(assert) {
this.$('button').click();

assert.equal(this.$('.ng-dirty').length, 0, 'inputs were reset');
});
});

test('works without using contextual components', function(assert) {
assert.expect(4);

this.render(hbs`
{{#paper-form as |form|}}
{{paper-input value=foo onChange=(action (mut foo)) label="Foo"}}
{{paper-input value=bar onChange=(action (mut bar)) label="Bar" errors=errors}}
{{#if form.isInvalid}}
<div class="invalid-div">Form is invalid!</div>
{{/if}}
{{#if form.isValid}}
<div class="valid-div">Form is valid!</div>
{{/if}}
{{/paper-form}}
`);

assert.equal(this.$('.invalid-div').length, 0);
assert.equal(this.$('.valid-div').length, 1);

this.set('errors', [{
message: 'foo should be a number.',
attribute: 'foo'
}, {
message: 'foo should be smaller than 12.',
attribute: 'foo'
}]);

assert.equal(this.$('.invalid-div').length, 1);
assert.equal(this.$('.valid-div').length, 0);
});

0 comments on commit 35d457f

Please sign in to comment.