Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finished Paper Form Component #408

Merged
merged 22 commits into from
Jul 10, 2016
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions addon/components/paper-form-container.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
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() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

destructure computed

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);
}
}
});
46 changes: 46 additions & 0 deletions addon/components/paper-form.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
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() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

destructure computed

return this.get('numberOfInvalids') === 0;
}),
isInvalid: Ember.computed('isValid', function() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

destructure computed

return !this.get('isValid');
}),
sendToParent: Ember.on('init', Ember.observer('isValid', function() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

destructure on

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

destructure observer

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);
}
}
});
3 changes: 3 additions & 0 deletions app/components/paper-form-container.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import PaperForm from 'ember-paper/components/paper-form-container';

export default PaperForm;
3 changes: 3 additions & 0 deletions app/components/paper-form.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import PaperForm from 'ember-paper/components/paper-form';

export default PaperForm;
1 change: 1 addition & 0 deletions app/templates/components/paper-form-container.hbs
Original file line number Diff line number Diff line change
@@ -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)}}
1 change: 1 addition & 0 deletions app/templates/components/paper-form.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{yield (hash validStatus=isValid isInvalid=isInvalid input=(component "paper-form-container" isTouched=isTouched onInvalid=(action 'onInvalid')) submit=(action 'submit'))}}
24 changes: 24 additions & 0 deletions tests/integration/components/paper-form-container-test.js
Original file line number Diff line number Diff line change
@@ -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');
});
24 changes: 24 additions & 0 deletions tests/integration/components/paper-form-test.js
Original file line number Diff line number Diff line change
@@ -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');
});