b421d19601
Also removes an observer that causes a "You modified 'disabled' twice in a single render" and executes the logic in the next run loop to prevent that error. That's not ideal but it's not time for a major refactoring of that part.
44 lines
1 KiB
JavaScript
44 lines
1 KiB
JavaScript
import { inject as service } from '@ember/service';
|
|
import Component from '@ember/component';
|
|
import { next } from '@ember/runloop';
|
|
|
|
export default Component.extend({
|
|
actions: {
|
|
addOption(element) {
|
|
let fragment = this.store.createFragment('option');
|
|
let options = this.options;
|
|
let position = this.options.indexOf(element) + 1;
|
|
options.insertAt(
|
|
position,
|
|
fragment
|
|
);
|
|
},
|
|
deleteOption(element) {
|
|
let position = this.options.indexOf(element);
|
|
this.options.removeAt(position);
|
|
}
|
|
},
|
|
|
|
enforceMinimalOptionsAmount() {
|
|
let options = this.options;
|
|
|
|
while (options.length < 2) {
|
|
options.pushObject(
|
|
this.store.createFragment('option')
|
|
);
|
|
}
|
|
},
|
|
|
|
store: service('store'),
|
|
|
|
init() {
|
|
this._super(...arguments);
|
|
|
|
// need to delay pushing fragments into options array to prevent
|
|
// > You modified "disabled" twice on <(unknown):ember330> in a single render.
|
|
// error.
|
|
next(() => {
|
|
this.enforceMinimalOptionsAmount();
|
|
});
|
|
}
|
|
});
|