I spent a few hours this morning working on some code that would duplicate this issue. I have been able to determine that the problem only occurs when using ColdFusion.Window.create. Using the cfwindow tag does not produce this issue.
The code below will duplicate the issue. The first part is the script for creating a window. This code creates a new window and destroys the previous. This is because refreshOnShow:true has no effect and my window loads dynamic content. The 2nd part of the code is the window content. This has a function to get the value of the form field in the window.
On first load everything is fine. However, once you close the window and open it up again the alerted value is now a list of values.
2
3<SCRIPT>
4winCounter = 1;
5winName = "window"+winCounter;
6
7function loadWindow(){
8 winH = 400;
9 winW = 300;
10
11 try{
12 ColdFusion.Window.getWindowObject(winName).destroy();
13 } catch (err) {}
14
15 winName = "window"+winCounter;
16 winCounter = winCounter+1;
17 ColdFusion.Window.create(winName, 'test window', 'test.cfm', {refreshOnShow:true,height:winH,width:winW,modal:true,closable:true, draggable:false,resizable:false,center:true,initshow:true});
18}
19
20</SCRIPT>
21<A HREF="JAVASCRIPT: loadWindow();">LOAD WINDOW</A>
window content file test.cfm
2 <input type="text" name="testField" id="testField" value="123" />
3</FORM>
4
5<A HREF="JAVASCRIPT: alert(ColdFusion.getElementValue('testField'));">SHOW VALUE</A>
There ya have it. Hopefully this can be addressed and fixed in future versions of CF.
--Dave
#1 by Brandon Wittwer on 10/17/07 - 7:06 AM
I'm not sure of your blog's comment ability.. so hopefully this looks right
[CODE]
var thelastwindow;
var editWindow = function editWindow(recordType){
var name = 'main'+Math.random()
var title = 'Create Org';
var width = 700;
var myurl='oogabooga.cfm'
var height = 700;
centered = true;
//options available{height:500,width:500,modal:true,closable:true, draggable:false,resizable:false,center:true,initshow:true}
var config = new Object();
config.width = width;
config.height = height;
config.centered = centered;
ColdFusion.Window.create(name, title,myurl,config);
ColdFusion.Window.onHide(name, windowClose);
}
var windowClose = function(name){
ColdFusion.Window.getWindowObject(name).body.dom.innerHTML = "";
thelastwindow = name;
}
[/CODE]
The onHide event passes the window name it fired from. and the body of a cfwindow has a dom elemental structure, so that gets access to the innerHTML property of the window and *poof*, all the extra copies of the form that are laying around in lala land disappear and you are left with 1 value per opened and closed window.
That very last bit about thelastwindow could be used to make sure any references to that window were also taken care of. it just drops the last deleted window into a global var for whatever you might need it for.
#2 by todd sharp on 10/17/07 - 7:40 AM
#3 by Brandon Wittwer on 10/17/07 - 7:47 AM
#4 by Dave Ferguson on 10/17/07 - 7:55 AM
if (winCounter != 1){
ColdFusion.navigate('test.cfm', winName);
ColdFusion.Window.show(winName);
return;
}
This actually worked. However, in the project I am working on this workaround it is not feasible. The demo code I posted is a subset of a much larger set of code for an interface. In this interface multiple windows are opened with varying sizes and content. I have to rebuild the window on every show so I can resize it and reload its content. Even with the destroy function the window is not completely destroyed thus my problem.
--Dave
#5 by Brandon Wittwer on 10/17/07 - 8:10 AM
Side note: does your formid change between windows that are interfering with eachother? I was testing the idea of opening multiple of the same form with different form ID's and it doesn't seem to pick up the correct form. i can upload examples if u like.
#6 by Brandon Wittwer on 10/17/07 - 8:12 AM
#7 by Dave Ferguson on 10/17/07 - 8:19 AM
Thanks,
--Dave
#8 by todd sharp on 10/17/07 - 8:21 AM
I see no reason why what you're trying to can't be done Dave - I'm a bit confused still I think but it should all work out for you.
To clarify things - CF.getElementValue() is not returning the wrong value - you were just adding that field to the DOM every time you showed the window so it returned the list of values.
#9 by Brandon Wittwer on 10/17/07 - 9:41 AM