Knockout bindings on text input value in iframe fail to update when code outside iframe updates the text input value: $('#myTextInputId).val('blah').change();

339 views
Skip to first unread message

Stewart Armbrecht

unread,
Jun 25, 2013, 8:33:09 AM6/25/13
to knock...@googlegroups.com
I have found that knockout text input value bindings in an iframe do not update when javascript code from outside the iframe updates the text input.  Is this a bug?  Any idea on how to get around this?

I am using a javascript UI test framework that loads the knockout page being tested in an iframe.  The test code uses jQuery to interact with the page in the iframe.  When I use jQuery's $('#myTextInputId).val('blah').change() to update the text box in the iframe the knockout binding does not update the underlying view model.  I have a working sample of this problem here:  http://stewartarmbrecht.droppages.com/myhtmlpage.html

In the sample there are 2 iframes.  
The first iframe loads a page with a text box and save button that displays when the text box value is not empty.  Code inside the 1st iframe page uses jquery to update it's own text input.  The save button displays itself.  
The second iframe loads the same page but this time the code inside the iframe does not update the text box.  Instead, javascript in the parent window updates the value of the text box. The problem is that the save button in the second iframe is not showing after the update. What I have found is that the knockout binding does not respond to the change event when it is raised by code from oustide the iframe.

Can anyone help me figure out how to get around this?  This is a major blocking bug for our UI automation strategy.

Thanks!!
Stewart 

rpn

unread,
Jun 25, 2013, 9:49:33 AM6/25/13
to knock...@googlegroups.com
I think there is an issue triggering the change event using the parent's instance of jQuery.

You should be able to something like:

document.getElementById("myIFrame").contentWindow.$("#insideTextBox").val("testing").change()

Stewart Armbrecht

unread,
Jun 25, 2013, 10:49:28 AM6/25/13
to knock...@googlegroups.com
Fantastic!!  That did it!  Thank you so much.  If you send an email to stewart dot armbrecht at protiviti dot com, I'll forward the reward I had offered my team.  :)
Reply all
Reply to author
Forward
0 new messages