admin管理员组文章数量:1278721
I need some help with selectize.js events - they dont work...
Inicialize selectize.js:
$("input[name='addTask[users]']").selectize({
valueField: 'email',
labelField: 'name',
//... more options like render...
});
And setting event:
$("input[name='addTask[users]']").selectize().on('type', function(){
alert();
});
If I typing in input nothing happens...
EDIT: No errors in console, selector is good because plugin works perfectly.
Only one event is working for me - "change".
Here si documentation:.js/blob/master/docs/events.md (Also I do not understand "params" - on what the needs are and what they do)
Any hints, ideas? Examlple it pleases me...
EDIT: OK I GOT IT!!! SO - SOLUTION:
In initialization selectize.js:
$("input[name='addTask[users]']").selectize({
valueField: 'email',
labelField: 'name',
onType : eventHandler('onType'), // <----- this added
//... more options like render...
});
and BEFORE initialization:
var eventHandler = function(name) {
return function() {
alert(name + ' ' + arguments['0']); // name of event + typed string
};
};
And alert work if you start typing in input :)
I need some help with selectize.js events - they dont work...
Inicialize selectize.js:
$("input[name='addTask[users]']").selectize({
valueField: 'email',
labelField: 'name',
//... more options like render...
});
And setting event:
$("input[name='addTask[users]']").selectize().on('type', function(){
alert();
});
If I typing in input nothing happens...
EDIT: No errors in console, selector is good because plugin works perfectly.
Only one event is working for me - "change".
Here si documentation:https://github./brianreavis/selectize.js/blob/master/docs/events.md (Also I do not understand "params" - on what the needs are and what they do)
Any hints, ideas? Examlple it pleases me...
EDIT: OK I GOT IT!!! SO - SOLUTION:
In initialization selectize.js:
$("input[name='addTask[users]']").selectize({
valueField: 'email',
labelField: 'name',
onType : eventHandler('onType'), // <----- this added
//... more options like render...
});
and BEFORE initialization:
var eventHandler = function(name) {
return function() {
alert(name + ' ' + arguments['0']); // name of event + typed string
};
};
And alert work if you start typing in input :)
Share Improve this question edited Dec 19, 2014 at 16:24 Lajdák Marek asked Dec 19, 2014 at 15:46 Lajdák MarekLajdák Marek 3,0898 gold badges32 silver badges60 bronze badges 1- What troubleshooting have you done? Have you looked in the browser console for errors? – Phil Tune Commented Dec 19, 2014 at 15:48
1 Answer
Reset to default 8Your issue is in this line:
$("input[name='addTask[users]']").selectize().on('type', function(){
alert();
});
You should have done:
$("input[name='addTask[users]']")[0].selectize.on('type', function(){
alert();
});
From the Docs: When initializing the control, the "selectize" property is added on the original / element—this property points to the underlying Selectize instance.
// initialize the selectize control
var $select = $('select').selectize(options);
// fetch the instance
var selectize = $select[0].selectize;
And Event Docs: Selectize instances have a basic event emitter interface that mimics jQuery, Backbone.js, et al:
var handler = function() { /* ... */ };
selectize.on('event_name', handler);
selectize.off('event_name');
selectize.off('event_name', handler);
本文标签: javascriptSelectizejs eventswont workStack Overflow
版权声明:本文标题:javascript - Selectize.js events - wont work - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741302908a2371198.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论