WIP
This commit is contained in:
parent
9ed63ca5ba
commit
dbcc51c80d
6 changed files with 69 additions and 19 deletions
39
app/pods/components/x-select/component.js
Normal file
39
app/pods/components/x-select/component.js
Normal file
|
@ -0,0 +1,39 @@
|
|||
import Ember from 'ember';
|
||||
|
||||
const { Component } = Ember;
|
||||
|
||||
export default Component.extend({
|
||||
tagName: 'select',
|
||||
|
||||
value: null,
|
||||
nameAttr: null,
|
||||
listItems: null,
|
||||
placeholder: null,
|
||||
selected: null,
|
||||
selectize: null,
|
||||
|
||||
attributeBindings: [
|
||||
'multiple',
|
||||
],
|
||||
|
||||
change: function() {
|
||||
this.attrs["update"](this.get('selectize').getValue());
|
||||
},
|
||||
|
||||
didReceiveAttrs: function() {
|
||||
this._super(...arguments);
|
||||
|
||||
if (!this.attrs.update) {
|
||||
throw new Error(`You must provide an \`update\` action.`);
|
||||
}
|
||||
},
|
||||
|
||||
didInsertElement: function() {
|
||||
this.$().selectize({
|
||||
plugins: ['drag_drop'],
|
||||
items: this.get('selected'),
|
||||
});
|
||||
this.set('selectize', this.$()[0].selectize);
|
||||
},
|
||||
|
||||
});
|
6
app/pods/components/x-select/template.hbs
Normal file
6
app/pods/components/x-select/template.hbs
Normal file
|
@ -0,0 +1,6 @@
|
|||
{{#if placeholder}}
|
||||
<option value="">{{placeholder}}</option>
|
||||
{{/if}}
|
||||
{{#each listItems as |option|}}
|
||||
<option value={{option.id}} selected={{equal option.id value.id}}>{{get-property option nameAttr}}</option>
|
||||
{{/each}}
|
Reference in a new issue