I wanna ask something about searching on selectize... for example i want to select football and basketball. I type in the search bar "ball", but when i click the option. the search text dissapear so i have to type it again. is there any possibility to keep the search text?
I need the same thing. Anyone has a solution to this?
has anyone been able to do this?
You can obtain this with a plugin extension. Try this:
/**
* Plugin: "preserve_search" (selectize.js)
* Based on: "preserve_on_blur" of Eric M. Klingensmith
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
* file except in compliance with the License. You may obtain a copy of the License at:
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
* ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
Selectize.define('preserve_search', function (options) {
var self = this;
options.text = options.text || function (option) {
return option[this.settings.labelField];
};
this.onBlur = (function (e) {
var original = self.onBlur;
return function (e) {
// Capture the current input value
var $input = this.$control_input;
var inputValue = $input.val();
// Do the default actions
original.apply(this, [e]);
// Set the value back
this.setTextboxValue(inputValue);
};
})();
this.onOptionSelect = (function (e) {
var original = self.onOptionSelect;
return function (e) {
// Capture the current input value
var $input = this.$control_input;
var inputValue = $input.val();
original.apply(this, [e]);
this.setTextboxValue(inputValue);
this.refreshOptions();
if (this.currentResults.items.length <= 0) {
this.setTextboxValue('');
this.refreshOptions();
}
};
})();
});
Then when you create you selectize set the plugin.
$('#selectizeId').selectize({plugins: ['remove_button', 'preserve_search']});
closing stale issues older than one year.
If this issue was closed in error please message the maintainers.
All issues must include a proper title, description, and examples.
Most helpful comment
You can obtain this with a plugin extension. Try this:
Then when you create you selectize set the plugin.
$('#selectizeId').selectize({plugins: ['remove_button', 'preserve_search']});