I'm working on essentially a WYSIWYG designer that allows the end-user to pick colors via [input type="color"] fields. This interface has the inputs on the left side and on the right side is an iFrame pointing to the generated preview. Typically, when an input is clicked and the color is changed, it calls function update (bound by a backbone view via change event on the input field). This update function then changes the CSS values in the iFrame for purposes of live preview. This is working fine.
However, I am building a unit test page that is essentially testing that changing an input field to a certain color will indeed change the color in the preview. Essentially this: "Change input to PINK. Did that input's corresponding CSS selector on the preview change to PINK?"
The structure of the unit test page is that the designer is loaded in via an iFrame. So now we have:
- Layer 0: unit test report
- Layer 1: color changing inputs
- Layer 2: real time preview
So here's the problem: When the unit tests are running, it successfully changes the value of the input fields but the subsequent change event doesn't seem to be caught by the view so the real time preview does not update.
Here is the code:
for (i in testable) {
item = testable[i];
item.element.val(tempColor);
item.element.trigger('change');
}
If I pull this out of the scope of the testing module and use the browser's console, this code has the same effect (input updates, but trigger never called):
$("#testFrame").contents().find('input#cat_RowColoralternate').val('#AAEFCC').trigger('change')
To prove that the event exists and does actually work, if I load it directly without the testing layer (e.g., loading application directly), this code works exactly how it's expected.
$(document).find('input#cat_RowColoralternate').val('#AAEFCC').trigger('change');
The only difference is the additional iFrame layer, so my theory is that the event isn't being propagated from layer 0 to layer 1.