Cf.Objective()

Adding a Preview tab to form - CF8

Comments (10) || ColdFusion 2423 Views

This is a quick entry showing how you can use the new cflayout tabs and the bind attribute of the cfdiv tag to quickly add a preview tab to a textarea form field.

<form action="" method="post">

<cflayout type="tab">

<cflayoutarea title="entry">
         <textarea name="textentry" rows="15" cols="50"></textarea>
   </cflayoutarea>
   
   <cflayoutarea title="Preview">
      <cfdiv bind="{textentry}">
   </cflayoutarea>

</cflayout>
   
<input type="submit" value="Save">
</form>

Edit - added demo page: Demo Link

Edit 2 - added rich text example: Rich Text demo



Comments

  1. That is truly interesting. I never thought to bind to a simple string. Does it work ok with HTML as well? Ie, using a rich text textarea.

  2. yep -

    <cfform action="" method="post">

       <cflayout type="tab">

        <cflayoutarea title="Entry Page">
             <cftextarea richtext="true" name="textentry" rows="15" cols="80"></cftextarea>
          </cflayoutarea>
       
          <cflayoutarea title="Preview">
             <cfdiv bind="{textentry}">
          </cflayoutarea>

       </cflayout>
       
       <input type="submit" value="Save">
    </cfform>

  3. Thats a cool use of cflayout. It works with rich text as well.

  4. Nice

  5. What if you want to prepopulate the textarea field like this?

    <cftextarea richtext="true" name="textentry" rows="15" cols="80">#myTextVal#</cftextarea>

  6. @Jeff: It would work fine.

  7. Actually, I tried it and it doesn't work until you type something new in to the textarea field.

  8. Sorry bit late to the game on this one!
    @Jeff you could use bindonload in the cfdiv

  9. Is there any way to have the cfdiv evaluate the bound content so that if I entered #now()# into the textarea field the date would show on the preview?

  10. Not really - the text you enter is being processed on the client side with javascript. I supposed you could use cfajaxproxy to send it back to the server and then update the output but I'm not sure I'd recommend that.

© 2007 Scott Pinkston, LLC || Design by N.Design Studio || Powered by BlogCFC || Entries RSS || Login