Thursday, February 21, 2008

Creating Tabbed Views in InfoPath 2007

This comes from: InfoPath Team Blog

InfoPath doesn't have a built-in Tab Control, but it's easy enough to build one using tables, buttons, and views, so let's do it!
The basic idea
Here's what to build:
  • Views for the contents of each tab
  • Table with shading to give the visual effect of tabs
  • Buttons for each tab with a rule that switches the view
For example:
Then when the user clicks "Details" they switch views to see this:
How To, with tricks along the way
  1. Create all of your views (from the Views task pane)
    • Select the same color scheme for each view (use the Color Schemes task pane)
    • Use Background Color on the Format menu to make the background of each view the second color for the current color scheme (the second-darkest color at the top of the color picker)
  2. Insert a layout table (on the Insert menu, click Table)
    • Make it two rows high. The first row will be for the buttons, the second will be for the tab content.
    • Split the first row to make a cell for each view, plus one extra cell to take the remaining horizontal space.
  3. Insert a button into each cell (from the Controls task pane)
    • Add a rule to each button to switch to the corresponding view. Do this even for the current view's button.
    • Make the current "active" button Bold, so it stands out.
  4. Use borders and shading (on the Format menu)
    • Select all the buttons at once (hold down the Control key and click each one), then remove all borders and shading from the buttons (they're invisible except for their label!).
    • Select the entire table, then add borders inside and out using the first color in the color scheme (the darkest color).
    • Select the non-active cells and set their shading to the third lightest color of the color scheme.
    • Select the active cell and the content cell, and set their shading to white.
    • Select the active cell and remove the bottom border so it becomes connected to the content cell.
    • Select the right-most "extra" cell and remove the top and right border
  5. Copy the table to each view
    • Update the borders and shading to change the "active" cell for each view
    • Put all your fields for each tab in its content cell
Getting fancy
If the tabs above aren't pretty enough for your form, add some images inside a few more table cells around each button to provide rounded corners and other visual effects. It's more work, and requires some image editing, but with a little elbow grease you could get something as schmancy as this:

8 comments:

  1. Very clever. Thanks for the tip!

    ReplyDelete
  2. Superb !!!

    Can you put more light on including images?

    ReplyDelete
  3. Hi,

    When open a form with multiple views, can it stay at the same view when it was created? it seems to display the default view regardless when the form was last saved...

    Thanks

    ReplyDelete
  4. I guess it would be something along the lines of enabling the user to save the last open view state of the form - a bit of custom code could potentially acheive this?

    ReplyDelete
  5. This could be a solution: http://www.infopathdev.com/forums/t/7554.aspx

    ReplyDelete
  6. Very nice post ... thank you!

    ReplyDelete
  7. This can be achived even without using the Views,
    Step 1 - Create a Table as explained above with two rows. Additionally keep one hidden text box.
    Step 2 - In the second Row add three sections and your controls inside these section.
    Step 3 - On click of those buttons set the hidden text with one value.
    step 4 - in all the Sections added in the second row, add the conditional formation based on the hidden value, and show only required section

    ReplyDelete
  8. Exactly what my manager asked me do! I have been looking for a solution.

    ReplyDelete