How do I work around the change in <cflocation> inside a CFC?

465 Views Asked by At

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.

1

There are 1 best solutions below

5
On

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".