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

validation for autocomplete and change to form #532

Merged
merged 2 commits into from
Oct 31, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 12 additions & 2 deletions addon/components/paper-autocomplete.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
*/
import Ember from 'ember';
import PowerSelect from 'ember-power-select/components/power-select';
import ValidationMixin from 'ember-paper/mixins/validation-mixin';
import ChildMixin from 'ember-paper/mixins/child-mixin';
import { indexOfOption } from 'ember-power-select/utils/group-utils';

const { assert, computed, inject, isNone, defineProperty, K: emberNop } = Ember;
Expand All @@ -11,7 +13,7 @@ const { assert, computed, inject, isNone, defineProperty, K: emberNop } = Ember;
* @class PaperAutocomplete
* @extends PowerSelectComponent
*/
export default PowerSelect.extend({
export default PowerSelect.extend(ValidationMixin, ChildMixin, {
util: inject.service(),
constants: inject.service(),
triggerComponent: 'paper-autocomplete-trigger',
Expand All @@ -26,7 +28,13 @@ export default PowerSelect.extend({
onblur: computed.alias('onBlur'),
onchange: null,
oninput: null,

validationProperty: computed('onSearchTextChange', 'onSelectionChange', function() {
if (this.get('onSearchTextChange')) {
return 'searchText';
} else {
return 'selected';
}
}),
searchText: '',
_onChangeNop: emberNop,

Expand Down Expand Up @@ -86,6 +94,7 @@ export default PowerSelect.extend({
if (action) {
action(this.get('publicAPI'), event);
}
this.notifyValidityChange();
},

onInput(event) {
Expand All @@ -94,6 +103,7 @@ export default PowerSelect.extend({
if (!publicAPI.isOpen && event.type !== 'change') {
publicAPI.actions.open(event);
}
this.notifyValidityChange();
return this._super(...arguments);
},

Expand Down
2 changes: 2 additions & 0 deletions app/templates/components/paper-autocomplete-trigger.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
label=extra.label
value=text
flex=true
required=required
customValidations=customValidations
disabled=(readonly disabled)
onChange=(action "handleInputLocal")
onFocus=(action onFocus)
Expand Down
2 changes: 2 additions & 0 deletions app/templates/components/paper-autocomplete.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@
searchEnabled=(readonly searchEnabled)
searchField=(readonly searchField)
searchText=(readonly searchText)
required=(readonly required)
customValidations=(readonly customValidations)
select=(readonly publicAPI)
selected=(readonly selected)
selectedItemComponent=(readonly selectedItemComponent)
Expand Down
8 changes: 8 additions & 0 deletions app/templates/components/paper-form.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@
parentComponent=this
onValidityChange=(action "onValidityChange")
)
select=(component 'paper-select'
parentComponent=this
onValidityChange=(action 'onValidityChange')
)
autocomplete=(component 'paper-autocomplete'
parentComponent=this
onValidityChange=(action 'onValidityChange')
)
onSubmit=(action "onSubmit")
)}}