Here's a jsfiddle to show what the issue is:
http://jsfiddle.net/boblauer/BgvV4/
I'm trying to fire the change event after a text field is updated. Unfortunately, inside the subscribe method, the text box's value hasn't been updated yet, so when I figure the change event, it's fired too soon.
I need to fire the change event because I have 3rd party code that is out of my control that relies on the change event.
Any suggestions?
A simple solution is to wrap your call to $("#text1").change() in a setTimeout with a timeout of 0. That's enough to let knockout do the (synchronous) update to the textbox value before the jquery change handler gets invoked.
I forked your fiddle to demonstrate: http://jsfiddle.net/SuRYa/1//
If this is something you need to do a lot, a better solution is probably to wrap this behavior in a custom binding where the "update" callback of the binding would fire the jquery change event on the updated element.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With