Ask a Jedi: Dynamic Selected Tab and Flash Form Recompiling

Gerald asks,

Ray, I am trying to get back to a tabbed page from my process.cfm by checking for the existance of the btn that submitted the form (each tab has it's own unique button for submitting to process.cfm). Then I set a URL var and cfrelocation back to the flash form where the selectedItem="#url.currtab#". Works great except the darn flash form reinitializes every time because that attribute gets changed. How can I do this without causing a recompile of the form?

Yes, it is possible - and this solution comes right from Mike Nimer (aka ‘The Flash Form Guy’). Instead of using selectedIndex=”#url.currTab#”, you can bind the value to a hidden form field. Consider:

<cfparam name="" default="0">

<cfform format=”flash” width=”400” height=”200” name=”foo”>

&lt;cfinput type="hidden" name="thetab" value=""&gt;
&lt;cfformgroup type="tabnavigator" selectedIndex="{foo.thetab.text}"&gt;

	&lt;cfformgroup type="page" label="Tab One" /&gt;
	&lt;cfformgroup type="page" label="Tab Two" /&gt;
	&lt;cfformgroup type="page" label="Tab Three" /&gt;
	&lt;cfformgroup type="page" label="Tab Four" /&gt;
&lt;/cfformgroup&gt; &lt;/cfform&gt;

<cfoutput> <a href=”#cgi.script_name#?tab=0”>Tab 1</a><br> <a href=”#cgi.script_name#?tab=1”>Tab 2</a><br> <a href=”#cgi.script_name#?tab=2”>Tab 3</a><br> <a href=”#cgi.script_name#?tab=3”>Tab 4</a><br> </cfoutput> </code>

Notice how the value for selectedIndex isn’t hard coded, but bound to the hidden form field. Also note how you have to use formname.fieldname when binding to a hidden field. For a non-hidden field, you can just use fieldname. Also note that the selectedIndex for a navigator item is 0 based - in other words, tab 1 is index 0, tab 2 is index 1, etc.

Enjoy - and again - thank Nimer for this tip. (Unless it is broken - then um - it is a Microsoft bug. Yeah, that’s it!)

Raymond Camden's Picture

About Raymond Camden

Raymond is a developer advocate. He focuses on JavaScript, serverless and enterprise cat demos. If you like this article, please consider visiting my Amazon Wishlist or donating via PayPal to show your support. You can even buy me a coffee!

Lafayette, LA