Skip to main content
August 31, 2007
Answered

Can't figure out how to create an update form in a cfwindow tag

  • August 31, 2007
  • 3 replies
  • 999 views
I finally was able to figure out how to do an add form inside of a cfwindow tag yesterday. But I want this form to be multipurpose, and allow edits as well. But for the life of me, I can't figure out how to pass a row of data to the form inside a cfwindow. Normally, I'd pass the primary key via the URL but if I try to do that here, it basically reloads the page and closes out the cfwindow since I have the window set to not show by default.

My page has a list of departments. My page is called departments.cfm. For each row in the department list, there is a link called edit. When the user clicks this link, I want the cfwindow to open with the cfform populated with the data from the department list for the row selected. Sounds simple enough, except how do I pass the department_id to the form? If my link is <a href="departments.cfm?id=#department_id#>Edit</a>, the cfwindow tag displays and I can see the data in it, but then closes right away. I finally figured out that it was calling the page again and the cfwindow is closing because I have it set to not display by default. I'm about ready to drop this cfwindow and just do real popup windows via javascript. And I'm normally not in favor of doing popup windows, but the application I'm working on doesn't have enough real estate on the screen to do a hidden form, so a separate window containing the form is my best solution.

Anyone have any suggestions?

    This topic has been closed for replies.
    Correct answer
    Thanks Peter,

    That worked!

    3 replies

    Known Participant
    September 1, 2007
    another thing to notice is the

    refreshOnShow="true"

    attribute in the CFWindow tag. This may be all you need.
    Known Participant
    September 1, 2007
    Well, this is kind of a tough one for me, but it sounds like the best way will be to launch a JavaScript function everytime the user clicks the link, like this:

    <cfoutput query="getDepartments">
    <a href="javascript:showWin(#yourID#)">show window</a>
    <br>
    </cfoutput>


    the showWin function will both create the window and launch it, passing in the user chosen var:

    function showWin(id) {
    var URL = 'editDeptPage.cfm?dept_id=' + id;
    var winName = 'deptWin' + id;

    ColdFusion.Window.create(winName, 'Edit the Department',
    URL,
    {x:100,y:100,height:300,width:400,modal:false,closable:true,
    draggable:true,resizable:true,center:true,initshow:true,
    minheight:200,minwidth:200 })
    }

    The following line of code is supposedly to make sure that the window refreshes each time it is launched, by naming it something new each time:

    var winName = 'deptWin' + id;

    However, if it doesn't work, I think there's a Window refresh function in the Ext library but I'm not sure.
    Also, in the showWin function, after the Window is created, you might need this but I'm not sure:

    ColdFusion.Window.show(winName)

    Talk to you later,

    Peter
    Correct answer
    September 5, 2007
    Thanks Peter,

    That worked!
    September 12, 2007
    in my case refreshOnShow is not working.

    As you can see below this is what I am using, and when the window shows up, it has the content which was in the window last time. i.e. I have a form inside that window, and once its submit it shows the result page. If ever I open the same window, it should show me the form, not the result page, but everytime when I use ColdFusion.Window.create() and that window is opened in the past, its not refreshing it.

    Please help.


    {refreshOnShow:true,center:true,modal:true,width:width4window,height:height4window});
    August 31, 2007
    OK, I'm getting closer to making this work. I've created separate Windows. One is called 'addWindow' and the other is called 'editWindow'. Here's my tag for the 'addWindow':

    <cfwindow name="addWindow" title="Add Window" initshow="false" source="/frmDepartment.cfm" />

    This one works great. Here's my tag for the 'editWindow':
    <cfwindow name="editWindow" title="Edit Window" initshow="false" source="/frmDepartment.cfm?id=#department_id#" />

    When I click on an Edit link in any of my rows (<a href="javaScript:ColdFusion.Window.show('editWindow')">Edit</a>) the window is displayed but its always using the department_id of the first row.

    For some reason, the department_id is not getting passed correctly to the cfwindow source attribute. Any ideas?