Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

Easy ftWatch Example

Here is a quick primer on how to use ftWatch in a formtool. Basically, two things get passed into the functions of a formtool (such as edit() or display()):

  1. stMetadata
  2. stObject

"stMetadata" is a structure that has all the metadata of the <cfproperty> tag that the call is made for. So, if you've defined ftWatch, it's value is sitting in "arguments.stMetadata.ftWatch". The stObject is all the data of the entire form (as it stands at the moment the function is called). So, say you define a string type to have a ftWatch="bBool", where bBool is the name of another <cfproperty> that you want to trigger on. When the value of that watched property changes, the edit() function of the string property is called. How do you know what the value is of the "bBool" property? Easy: the stObject!

Ok, let's get more specific. Put the following code in any formtool you extend. Such as a simple extend of a farcry.core.packages.formtools.string. Put it in the function edit() or display() right after the <cfset var html="">. Delete everything else in the function except <cfreturn html>.

ftWatch Example
        <cfif structkeyexists(arguments.stMetadata,"ftWatch") and len(arguments.stMetadata.ftWatch)
            AND structkeyexists(arguments.stObject,"#listfirst(arguments.stMetadata.ftWatch)#")
            AND isValid("boolean",arguments.stObject[listfirst(arguments.stMetadata.ftWatch)])
            AND NOT arguments.stObject[listfirst(arguments.stMetadata.ftWatch)] >
            <cfset html=""/>
        <cfelse>
            <cfset html = super.edit(argumentCollection="#arguments#") />
        </cfif>

The <cfif> structure is simply there to check that all the proper metadata exists and that it is of the proper type. Then to actually check the value, you call

arguments.stObject['bBool']

. Of course, since you want this to work no matter what the name of either property, everything has to be a variable!

What the code above does is check if ftWatch is defined, if it is, and the watched property is a boolean, AND if that boolean is 'false' (or '0' or 'no'), then 'html' (which is returned as the thing to display) will be empty. For all other cases (such as ftWatch not being defined, the boolean being true, or the property not existing) the normal html will show.

Of course, we could also put in a function instead of a simple '<cfset html=""/>' and get all manner of fancy. But let's start simple, eh?

  • No labels