Flash Forms – Using BIND for more than just your {AS}
I learned something great today and I thought I’d share it with everyone. It turns out that you can use “BIND=” for more than just including the bind when you’re binding a CFFORM flash item to something else. In the past, I’ve used BIND like so:
1 | <cfitem type="text" bind="{grContacts.dataProvider[grContacts.selectedIndex]['FULL_NAME']}" /> |
Which would bind this item to the currently selected FULL_NAME in a CFGRID tag. However, what if I wanted to greet this person in the text area? I used to do this:
1 2 | <cfformitem type="text">Good Morning </cfformitem <cfformitem type="text" bind="{grContacts.dataProvider[grContacts.selectedIndex]['FULL_NAME']}" /> |
This, however, would cause me to have to do some pretty nutty formatting and sizing so that they sat next to each other. Most of the time, I wouldn’t bother. But I’ve learned different now, and I can now code the pages as follows:
1 | <cfformitem type="text" bind="Good Morning {grContacts.dataProvider[grContacts.selectedIndex]['FULL_NAME']}" /> |
Notice you can put non AS {stuff} into your BIND? Pretty sweet. You can also do formatting in there (if you’re using TYPE=”HTML”). If it’s anything more than a few words, you’ll probably want to set the variable ahead of time, and then bind to that variable such as this:
1 2 3 4 | <cfsavecontent variable="bindGreeting"> Good Morning, {grContacts.dataProvider[grAllocations.selectedIndex]['FULL_NAME']}, it's great that you've come back! </cfsavecontent> <cfformitem type="text" bind="#bindGreeting#" /> |
For what it’s worth, I can’t think of any situation where I’d greet a name based on a binding to a CFGRID, but there are obviously plenty of good real life uses for this.
