У меня есть ввод selectize, и я хочу изменить его поведение. Обычно я использую входы selectize из какой-то структуры (блестящие), поэтому надеюсь, что пример, который я привожу здесь, понятен и точен.
Я хочу изменить логику, когда происходит событие onChange срабатывает. Я хочу, чтобы это происходило только тогда, когда выбран один элемент, а не когда ни один не выбран. В случае, если пользователь удаляет элемент и оставляет форму нетронутой, я хочу восстановить значение, которое было активным ранее.
Взгляните на следующий код:
Код: Выделить всё
$(document).ready(function() {
var selectize = $('#select-beast').selectize({
delimiter: ',',
persist: false,
create: function(input) {
return {
value: input,
text: input
}
}
});
selectize[0].selectize.on('change', function() {
var value = selectize[0].selectize.getValue();
console.log(value);
});
});Код: Выделить всё
Selectize Example
[*]
Lion
Tiger
Bear
Elephant
Rhino
So in my case the log message should only ever print out something like Array["bear"] but never an empty array. I know that in this case one could do a if before the console.log but I am explicitly asking for changing the onChange condition because in my real problem I have no direct control on what my framework is doing. Is there a way of achieving my goal?
- no change-event with empty selection
- restoring the value that was there before, once the user gives focus to another element
Источник: https://stackoverflow.com/questions/781 ... tize-input
Мобильная версия