Microsoft InfoPath 2010
The official blog of the Microsoft InfoPath team

June, 2004

  • Microsoft InfoPath 2010

    Collapsible Sections

    • 6 Comments

    Collapsible Sections

     

    Mark asks:

     

    How do I create a collapsible section? That is, a section that can show/hide child controls, whether they are required or not. I can't use an optional section, because it requires binding.

     

    The easiest way to do this is to this is using Conditional Formatting. Select the Section control, then pick Format | Conditional Formatting.... Add a rule where the formatting is “Hide this control”.

     

    Adding conditional visibility to a section

     

    We often call this “conditional visibility.” Like everything in InfoPath, the view state is driven entirely by the data, so you need something in your data which maps to the expand/collapse state. One common approach is to add an attribute field to the group element the section is bound to. It shows up in your data when saved, and the expand/collapse state is saved when users save the form.

     

    Designing a collapsible section

     

    Bind a checkbox to the attribute, and you now have UI which lets the user control the state. If you prefer a button, you can create a rule which sets the value of the attribute; use two buttons with more conditional visibility rules to swap the label (e.g. between a + and a – to look like a TreeView). You can also write code which modifies the value of the attribute, and the section will show or hide.

     

  • Microsoft InfoPath 2010

    Use patterns (e.g., digits or quotes) to validate data in InfoPath

    • 3 Comments

    Example 1: How do I restrict the user from entering special characters into certain fields in the InfoPath Form?

    Note: This example assumes you are running InfoPath 2003 with the SP-1 feature enhancements enabled. [Added 6/21/04]

    The easiest way to do this is to use pattern for data validation. For example, you might want a user to enter data in the ###-##-#### format for the Social Security Number field. If the user’s input does not match this format, you may want to throw an alert. You can achieve the above by doing the following:

    1. In Design mode, insert a Textbox Control
    2. Double click on the Textbox Control to get the properties dialog box
    3. Click on Data Validation | Add
    4. Choose “does not match pattern” from the second dropdown and “select a pattern” from the third dropdown
    5. Click on “Social Security number” from the standard patterns dialog

      Picture of the Data Entry Pattern dialog
    6. Click OK to accept the changes
    7. In the Data Validation dialog, choose “Dialog box alert” from the Error alert type dropdown and specify some alert message

      Picture of the Validation dialog
    8. Click OK to accept the changes
    9. You can test your form by clicking on the Preview Form button, in the toolbar  

    Example 2: I cannot put a double quote (“) or an apostrophe (‘) in the pattern builder. How do I validate data against a pattern that contains a double quote (“)?

    You can validate data against a pattern that contains double quotes by using Jscript regular expression. For example, you might want a user to enter data in the “###” format (a pattern contains double quotes) for a field. If user’s input does not match this format, you may want to throw an alert. You can achieve the above by doing the following:

    1. In Design mode, insert a Textbox Control
    2. Double click on the Textbox Control to get the properties dialog box
    3. Click on Data Validation
    4. In the Script section, choose “OnAfterChange” from the dropdown and Edit

    Picture of the Data Validation dialog

    1. Add the followings to your code  

    function msoxd_my_field1::OnAfterChange(eventObj)

    {

    // Write code here to restore the global state.

                    if (eventObj.IsUndoRedo)

                        {

    // An undo or redo operation has occurred and the DOM is  read-only.

                                    return;

                         }

     

    // A field change has occurred and the DOM is writable. Write code here to respond to the changes

     

                    // Specify your pattern using Jscript regular expression

                    var re1 = new RegExp(“\x22\\d\\d\\d\x22”);

     

                    // Get the field value

    var s = XDocument.DOM.selectSingleNode(“my:myFields/my:field1”).text;

     

    // Find a match within string s

    if (re1.exec(s) = = null && eventObj.Operation = =  “Insert”)

                    XDocument.UI.Alert(“User input does not match the required pattern”);

                    }

     

    1. After editing all the code, click OK to accept the changes
    2. You can test your form by clicking on the Preview Form button, in the toolbar
  • Microsoft InfoPath 2010

    Recursive Controls support in InfoPath 2003 SP1

    • 3 Comments

    The SP1 release of InfoPath 2003 supports recursive controls such as Repeating Recursive Section and Optional Recursive Section. Based on the schema of the solution, these controls are automatically suggested when dragging nodes from the Data Source task pane. This article talks about different types of recursion that are supported within InfoPath.

    Direct Recursion:

    This is the case when the node is recurring directly under itself. For example, if you are creating an organization chart, you might have a schema that has the following structure:

    Employee*

    EmployeeData

    ID
    Name
    …..

    Employee*

    Every employee has EmployeeData associated with him and can have 0 or more employees working for him. Note that the * stands for repeating 0 or more times. If you select the top level Employee node in the Data Source task pane, InfoPath would suggest a Repeating Recursive Section in this case with the recursive instance showing up directly under its parent.

    Picture of design mode for the direct recursion structure

    Indirect Recursion:

    This is the case when the node is recurring as a child of another node within itself. For the above organization chart, you may choose to abstract the fact that Employee is a manager or not by introducing an Optional node Manager. In this case the structure is as follows:

    Employee*

    EmployeeData

    ID
    Name
    …..

    Manager?

    ManagerData

    ID
    Name
    NumOfReports
    …..

    Employee*

    In this case, when you drag top level Employee node, InfoPath will create a Repeating Recursive Section that has the recursive instance within an Optional Section that corresponds to Manager node.

    Picture of design mode of the indirect recursion structure

    Potential Recursion:

    This is the case when the node is recurring under as one of the choices under itself. Again taking the above organization chart example, we may choose to not include EmployeeData for managers since it is covered under ManagerData. So now we could have the following structure:

    Employee*

    Choice

    Non-Manager

    EmployeeData
    ID
    Name
    …..

    Manager

    ManagerData
    ID
    Name
    NumOfReports
    …..

    Employee*

    Now we have an employee who can either be a manager or not. In this case, when you drag top level Employee node, InfoPath will create a Repeating Recursive Section that has the recursive instance within a Choice Section.

    Picture of design mode of the potential recursion structure

    In summary, you have seen how InfoPath supports various types of recursion in its SP1 release. These three examples were just to illustrate the broad categories of recursion but you can go beyond these and try various other combinations based on your needs.

  • Microsoft InfoPath 2010

    Calling SelectText (and other InfoPath methods with optional parameters) in C# or VB.NET

    • 2 Comments

    In the introduction to SP1, InfoPath added C# support. One issue that some people may run into is that certain OM calls have optional parameters. One such method is the SelectText() method in the View object. The context ID is optional and it not always easily found. In JavaScript of VBscript, the optional parameter would just be omitted and everything would work. In managed code (C# and VB.NET), you cannot omit optional parameters. To get around this, managed code has System.Reflection.Missing.Value which can be used in place of the optional parameter. This will achieve the same result as omitting optional parameters.

  • Microsoft InfoPath 2010

    Introducing Microsoft® Office InfoPath™ 2003

    • 1 Comments

    Microsoft Learning and Roger Jennings have a new book out through Microsoft Press - Introducing Microsoft® Office InfoPath™ 2003. This book covers InfoPath from top to bottom including the SP-1 feature enhancements and developing InfoPath solutions using managed code.

    From the book's description:
    "Learn how to integrate forms with other Microsoft products such as Microsoft SQL Server and Access databases, Windows SharePoint Services, and XML Web services. This book also provides an overview of the technologies used to build an InfoPath forms solution using Visual Basic .NET managed code and the InfoPath Document Object Model (DOM)."

    You can find a little more information, including how to order, at http://www.microsoft.com/mspress/books/6511.asp.

     

Page 1 of 1 (5 items)