Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

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

Code Block
titleftWatch Example

  
     <cfif structkeyexists(arguments.stMetadata,"ftWatch") and len(arguments.stMetadata.ftWatch)
            	AND structkeyexists(arguments.stObject,"#listfirst(arguments.stMetadata.ftWatch)#") 
	AND ( 
        AND 			( isValid("boolean",arguments.stObject[listfirst(arguments.stMetadata.ftWatch)]) 
				AND NOT arguments.stObject[listfirst(arguments.stMetadata.ftWatch)] )
			OR NOT      AND NOT len( arguments.stObject[listfirst(arguments.stMetadata.ftWatch)] )
		)	>

	<cfsavecontent variable="jsscript"><cfoutput>
		<script type='text/javascript'>
			var el = Ext.get('#arguments.fieldname#ajaxdiv')
			if (null != el) {
				if (el.parent("div").parent("div").is('div.fieldSection') ) {
					el.parent("div").parent("div").setStyle('display','none');
				}
			}
		</script>
	</cfoutput></cfsavecontent>

	<cfset html ="" jsscript />
	
<cfelse>
	<cfsavecontent variable="jsscript"><cfoutput>
		<script type='text/javascript'>
			var el <cfelse>
            = Ext.get('#arguments.fieldname#ajaxdiv')
			if (null != el) {
				if (el.parent("div").parent("div").is('div.fieldSection') ) {
					el.parent("div").parent("div").setStyle('display','block');
				}
			}
		</script>
	</cfoutput></cfsavecontent>
	<cfset html = jsscript & 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

...

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') or if the value has zero length (in case there is no ftDefault defined), 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.

The javascript is there to look up the entire row of the form and hide it from view, so that you don't have a label hanging out by itself! Neat, huh?

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