-
-
Notifications
You must be signed in to change notification settings - Fork 333
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
Changes from 9 commits
cc5b673
5745ed6
90cf27f
643f458
1f56862
d804a78
d3e5163
68f497c
bc3c3db
f306ca1
9513e2e
6cd51af
76f6e4d
f9f99d6
5eccc4b
5eb24fe
21d8648
88c9033
011b9f0
a7bb8bd
f09a160
a9e236c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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() { | ||
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); | ||
} | ||
} | ||
}); |
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() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. destructure |
||
return this.get('numberOfInvalids') === 0; | ||
}), | ||
isInvalid: Ember.computed('isValid', function() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. destructure |
||
return !this.get('isValid'); | ||
}), | ||
sendToParent: Ember.on('init', Ember.observer('isValid', function() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. destructure There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. destructure |
||
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); | ||
} | ||
} | ||
}); |
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; |
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; |
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)}} |
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'))}} |
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'); | ||
}); |
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'); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
destructure
computed