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

Allow the users to type in selectize single selects. #776

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
29 changes: 29 additions & 0 deletions examples/plugins.html
Expand Up @@ -113,6 +113,35 @@ <h2>Plugin: "dropdown_header"</h2>
})
</script>
</div>

<div class="demo">
<h2>Plugin: "typing_mode"</h2>
<div class="control-group">
<label for="select-language">Languages:</label>
<select id="select-language" placeholder="Select a language...">
<option value="txt">Text</option>
<option value="md">Markdown</option>
<option value="html">HTML</option>
<option value="php">PHP</option>
<option value="python">Python</option>
<option value="java">Java</option>
<option value="js">JavaScript</option>
<option value="ruby">Ruby</option>
<option value="vhdl">VHDL</option>
<option value="verilog">Verilog</option>
<option value="c#">C#</option>
<option value="c++">C/C++</option>
</select>
</div>

<script>
$('#select-language').selectize({
plugins: ['typing_mode'],
persist: false,
create: true
});
</script>
</div>
</div>
</body>
</html>
35 changes: 35 additions & 0 deletions src/plugins/typing_mode/plugin.js
@@ -0,0 +1,35 @@
Selectize.define('typing_mode', function(options) {
var self = this;

this.setup = (function() {
var original = self.setup;

return function() {
original.apply(this, arguments);

this.on('dropdown_open', function() {
self.typingValue = self.typingValue || self.getValue()
var option = self.getOption(self.typingValue);

self.$control_input.attr('placeholder', option.text().trim());
self.$control_input.css({
opacity: '1',
width: '100%',
position: 'relative'
});
self.$control.find('.item').hide();

self.items = [];
self.setCaret(0);
});

this.on('change', function() {
self.typingValue = self.getValue();
});

this.$control_input.on('blur', function() {
self.setValue(self.typingValue);
});
};
})();
});