mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-15 03:12:54 +03:00
3fa48960f8
no issue - modify behaviour of selectize's `openOnFocus` option by ensuring that the dropdown is not opened when the input field is blank - fixes issue with dropdown opening when content is loaded async despite `openOnFocus=false` - fixes issue with dropdown remaining open when user enters text then deletes it
47 lines
1.5 KiB
JavaScript
47 lines
1.5 KiB
JavaScript
import Ember from 'ember';
|
|
import EmberSelectizeComponent from 'ember-cli-selectize/components/ember-selectize';
|
|
|
|
export default EmberSelectizeComponent.extend({
|
|
|
|
_dontOpenWhenBlank: Ember.on('didInsertElement', function () {
|
|
var openOnFocus = this.get('openOnFocus');
|
|
|
|
if (!openOnFocus) {
|
|
Ember.run.next(this, function () {
|
|
var selectize = this._selectize;
|
|
selectize.on('dropdown_open', function () {
|
|
if (Ember.isBlank(selectize.$control_input.val())) {
|
|
selectize.close();
|
|
}
|
|
});
|
|
selectize.on('type', function (filter) {
|
|
if (Ember.isBlank(filter)) {
|
|
selectize.close();
|
|
}
|
|
});
|
|
});
|
|
}
|
|
}),
|
|
|
|
/**
|
|
* Event callback that is triggered when user creates a tag
|
|
* - modified to pass the caret position to the action
|
|
*/
|
|
_create(input, callback) {
|
|
var caret = this._selectize.caretPos;
|
|
|
|
// Delete user entered text
|
|
this._selectize.setTextboxValue('');
|
|
// Send create action
|
|
|
|
// allow the observers and computed properties to run first
|
|
Ember.run.schedule('actions', this, function () {
|
|
this.sendAction('create-item', input, caret);
|
|
});
|
|
// We cancel the creation here, so it's up to you to include the created element
|
|
// in the content and selection property
|
|
callback(null);
|
|
}
|
|
|
|
});
|