1

This post addresses the problem I'm having.

Coldfusion 8 doing both CFIf and the CFElse statement?

My cfselect has a bind to a CFC to build its array dynamically. Ok, now I want to add an array item "--New Record--" and when that is selected, jump over cflocation to the form that allows the user to add a new record in the source table. I can see the "--New Record--" entry in the cfselect list, but selecting it appears to do nothing.

But actually, cflocation goes to the target page (I have OnRequestEnd logs to prove it) but the form of the target page is not displayed.

It looks like this topic was not resolved in the discussion above. Ben Nadel's Blog has highlighted the change in <cflocation> behavior, but I am new so I don't presume to understand the implications or how to get around the change in functionality. Any help in how to code around this (strange) change in behavior would be greatly appreciated.

TIA.

Community
  • 1
  • 1
  • Do you have a link to his blog entry and some of the code from it? – James A Mohler Feb 01 '13 at 23:28
  • 7
    Some sample code would also help a lot, otherwise we're grasping at straws. – Busches Feb 02 '13 at 01:00
  • 2
    Please don't *describe* your code, just *post it*. We'll understand your code better than your description of it. I cannot make head or tail of what your problem is based solely on your description. – Adam Cameron Feb 02 '13 at 09:21
  • Here is the link to Ben Nadel's CF Blog entry about this issue: http://www.bennadel.com/blog/2050-Changes-In-CFLocation-OnRequestEnd-Behavior-In-ColdFusion-9-s-Application-cfc.htm – Walt Palmer Feb 04 '13 at 21:36

1 Answers1

0

In your cfc, change your query from something like this:

    SELECT  id_field, text_field
    FROM    sometables
    WHERE   ... 

to

    SELECT   -1 AS id_field, 'Add New Record' AS text_field
    FROM     some_small_table
    WHERE   ... 
    UNION
    SELECT   id_field, text_field
    FROM    sometables
    WHERE   ... 
    ORDER BY id_field

That way your bind will still work and you will have your "Add New Record" selection.

Next, add an onBlur attribute to your cfselect. Have it call a javascript function that directs the user to the appropriate place if they select "Add New Record".

Community
  • 1
  • 1
Dan Bracuk
  • 20,699
  • 4
  • 26
  • 43
  • Thanks Dan, let me include the code this time. function fnSelectWithNew(keyfld) { alert ("Please select one"); if (keyfld == '--New--') { location.replace("assetTypeCreate.cfm"); } else { alert ("Please select one"); document.formname.fieldname.value = ""; return false; } } As noted, it goes to AssetCreate.cfm but doesn't display the form. – Walt Palmer Feb 04 '13 at 18:37
  • Sorry, new here. Learning mode. The problem is NOT getting the "New" entry to appear. The problem is that the or equivalent Javascript goes to the target but doesn't display the entry form. Then immediately returns to the original form. I need to use binds because I have dynamic dropdowns that require client interaction and response. "New" is intended to be a viable response that should stop editing this record and jump to a new form to get the new code. I'll try to cut down the code to fit here. – Walt Palmer Feb 04 '13 at 22:33
  • // My .CFM function fnSelectWithNew(keyfld) { if (keyfld == '--New--') { location.replace("assetTypeCreate.cfm"); } else { ... } } – Walt Palmer Feb 04 '13 at 23:01
  • // bindfcns.cfc SELECT DISTINCT(assetType) FROM AM_assetType – Walt Palmer Feb 04 '13 at 23:08
  • Sorry team; I've read the formatting instructions to make a block (indent 4 spaces); but it isn't working for me. I really TRIED to format my code. It looks formatted when I edit it. :( – Walt Palmer Feb 04 '13 at 23:09