I am not getting the value input box when I am using keypress event.

51 views
Skip to first unread message

clagtech....@gmail.com

unread,
Dec 1, 2017, 6:35:30 AM12/1/17
to KnockoutJS
how can we call a function on keypress event and then pass the value to function and get the desire result.

I want to make autocomplete dropdown .

clagtech....@gmail.com

unread,
Dec 6, 2017, 12:53:40 AM12/6/17
to KnockoutJS
ko.computed got the answer

Jean-Sebastien Binette

unread,
Dec 9, 2017, 8:34:10 AM12/9/17
to KnockoutJS
look into chosen jquery.
I combined this with a custom binding like so

ko.bindingHandlers.chosenOptions = {
init: function(element, valueAccessor, allBindings, data, context) {
var options = allBindings().chosenOptionsOptions || {}
ko.bindingHandlers.options.init(element, valueAccessor, allBindings, data, context)
var temp = $(element).chosen(options);
/*
*From what I can see, a width NEEDS to be set with chosenOptionsOptions: {width: "300px"} for the thing to work.
*Also, the object selected MUST come from the list, so you do a javascript find on the list to set it and everything will work.
*/
//This binds the jqueryChosen object to the chosenOptionsChosenObject variable name in the model
//It is used to add things to a multiple select
//in the html data-bind, add chosenOptionsChosenObject with a variable name
//this variable in the model is set to chosen.
//example
//say you want to insert this result: self.emailsChosenObject.results_data[17]
// you pick the html li thing by var temp = $('.chosenEmails *[data-option-array-index="17"]');
//you set self.emailsChosenObject.result_highlight = temp;
//then you call self.emailsChosenObject.result_select(new Event("email")) //you put the event to prevent a console error only
if (allBindings().chosenOptionsChosenObject) data[allBindings().chosenOptionsChosenObject] = temp.data().chosen

},
update: function(element, valueAccessor, allBindings, data, context) {
ko.bindingHandlers.options.update(element, valueAccessor, allBindings, data, context)
setTimeout(function() {
$(element).trigger('chosen:updated')
}, 50)
}

Reply all
Reply to author
Forward
0 new messages