Using keypress event in knockout JS
I'm trying to read the contents of an html textbox and fetch data from my
DB to accomplish a google type auto complete. I'm using twitter bootstrap
typeahead for the auto complete functionality. For that I need to record
keys as they are pressed and make a call to my DB with the query text to
the DB.
The html for the text box is this
<input id="query" data-bind="value: query, valueUpdate: 'keypress', event:
{ keypress: check }"/>
My assumption was that this will update the value in the viewmodel as soon
as the key is pressed, and the check function will meanwhile call the DB.
But the call is made to check( ) and the text box never gets populated
when the user types. if the JS looks like this -
function check() {
alert("Hello");
}
For every key I press, hello pops up but the text box in the HTML UI does
not show the key that was pressed/does not record which key was pressed.
How do I record the key press and send the request simultaneously?
See http://knockoutjs.com/documentation/textinput-binding.html
ReplyDelete