Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change event doesn't trigger when Knockout updates value

I have an external javascript library which triggers on the change of a textarea, formats it, etc.

However, when KnockoutJS sets the value to the textarea, the change event isn't fired. Simplified Fiddle of my problem. Is it possible to fire the change event when Knockout updates the value of my textarea?

like image 934
Jesse van Assen Avatar asked Jun 21 '12 08:06

Jesse van Assen


1 Answers

Rather than trying to force Knockout to work with change events you can setup a subscription on the underlying observable. Like this: http://jsfiddle.net/EZC9E/1/

this.text.subscribe(function(newValue) {
    alert('Text is changing to ' + newValue);
});        
like image 96
John Earles Avatar answered Oct 13 '22 11:10

John Earles