Microsoft InfoPath 2010
The official blog of the Microsoft InfoPath team

Save the Date! Using Horizontal Repeating Sections

Save the Date! Using Horizontal Repeating Sections

Rate This
  • Comments 5
InfoPath 2007 introduces a new flavor of the repeating section control - horizontal repeating section. It is useful when you want to present or edit repeating data in a structured format. When new items are added, they show up side-by-side with the existing items instead of one on top of the other.
 
Horizontal repeating section is a new building block for layouts. In my previous post about horizontal repeating tables, we discussed how a horizontal repeating table is a combination of a horizontal repeating section and layout tables. You can make your own new layouts by using this new control.
 
For example, one cool use of a horizontal repeating section is a "calendar" - style form:
 
Play with it!
Download the form template and try a few things (requires InfoPath 2007, and save it to your computer before opening it):
  1. Switch to a different month by using a dropdown on top of the form.
  2. Add a note for a day.
  3. Add a note with an exclamation sign (i.e. "presentation!") - notice the day turning red.
  4. Switch views to the summary view, and observe all appointments as a flat list.
  5. Open the form template in design view, and view its logic by going to Tools | Logic Inspector.
 
How it's done
In this form, each day in the calendar is displayed by using a horizontal repeating section; only the header ("Monday, Tuesday, Wednesday…") is static. To accomplish this, we are using several powerful tricks:
 
  1. Calendar generation is completely dynamic. To generate a view of a different month, we are setting the following fields in the form under myFields/currentMonth:
    • firstDay [date field in XML format (YYYY-MM-DD); set to the first day of the month that you want to view the calendar for - i.e. for May 2007, set to "2007-05-01"]
    • numberOfDays [integer; number of days in the month that you want to present; i.e. for May 2007, set to "31"]
    • mondayOffset [integer; weekday of first day of the month; Sunday=0, Monday = 1, Tuesday = 2, etc. I.e. for May 2007 that starts on Tuesday, set to "2"]

    Note that if you wanted to extend this calendar to show additional months, you could do so by adding rules to set these parameters for different months. It's also easy to move this logic to a web service or form code - thus eliminating the need to maintain a static list of months.
     
  2. Horizontal Repeating Sections wrap when placed inside a table. The wrapping point is determined by table width. This allows us to set up a 7-day-long week.

  3. Conditional formatting works just as expected on horizontal repeating sections. This allows us to highlight today's date, set red background for days marked with an exclamation sign, and set correct background color for weekends.

  4. Default values help us create a necessary number of instances of the horizontal repeating section to cover for the longest month, even if it starts on Saturday. We need 6 instances to cover for "blank" days before the first day of the month, plus a maximum of 31 days in a month = 37 instances. To accomplish this, you can follow the technique from this article.

  5. Rules provide a mechanism for month selection: when a month is selected from the dropdown on top of the form, correct values are set for nodes under myFields/currentMonth.
 
Of course, there are many uses beyond a calendar, otherwise we would have just built a calendar control, but we couldn't resist sharing this example because it shows off so many tricks.
 
Alex Weinstein
Program Manager
Attachment: Calendar.xsn
Leave a Comment
  • Please add 1 and 6 and type the answer here:
  • Post
  • Love the idea of a horizontal repeating table - could have used this in previous projects.

    One thing - I intensely dislike have to click twice to move from Views to Data Source or Controls ect. in the sidebar.  I really see Design Checker and Publish Form Template as being in a different place, and used less often.  It appears these additions are the reason for the design change - is this correct?
  • Glad to hear you can use the horizontal repeating table!

    Also thanks for the feedback on the switching between task panes. We're aware this can be cumbersome and are already looking at ways to make this easier in future versions.

    - Ned
  • We encountered an issue with horizontal repeating controls not wrapping in a particular case.

    If you send the form in email and include a static copy of the form (rather than dynamic) the generated screen shot doesn't wrap the horizontal control, but rather stretches it out to infinity on the right.

    The form renders fine interactively inside a table of specified width. It's only when emailing a static copy of the form that we've encountered the problem.

    InfoPath 2007 BTR2

  • To HazenHills: thank you for reporting the issue. We are aware of this limitation; unfortunately, there is no good way to preserve the layout of this kind of form in the Outlook preview pane. One workaround would be to place the horizontal repeating section into a scrolling region: this will cut off everything outside of the borders of the scrolling region. Alternatively, you can attach the form XML with the email message, and the user will be able to see the correct layout by double-clicking on the email message.

    - Alex

  • I know this is a very old post, but is there some way to still download the form template for this project?

Page 1 of 1 (5 items)