Is there a way to use the ⏎ or Enter key as delimiter for a selectize multiselect field? Unfortunately I could not find anything about the delimiter at all, either in the docs nor via Google (explicitly for my case).
The default settings should look like this:
$('#input-tags').selectize({
delimiter: ',',
persist: false,
create: function(input) {
return {
value: input,
text: input
}
}
});
So it seems that only regular chars are allowed?!
Rory's answer will work however it will not prevent auto-completion on enter. To ensure you always get a new item on enter use the plugin
Selectize.define('enter_key_delim', function (options) {
var self = this
this.onKeyDown = (function (e) {
var original = self.onKeyDown
return function (e) {
if (e.keyCode === 13) {
self.createItem();
e.preventDefault();
} else {
return original.apply(this, arguments);
}
}
})()
})
Then in your options for the selectize element use plugins: ['enter_key_delim']
,
如果插件构建了可在split()
方法中使用的正则表达式,则应该能够为delimiter
属性提供\\r
或\\r\\n
,如下所示:
delimiter: '\r\n'
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.