InfoPath 2007 Contact Selector – Require a selection

Updated: Click here for an example of how to achieve the same functionality without any code.

The following solution will require a Full Trust form with code, but will allow for a Contact Selector to be placed on a browser-based InfoPath form which will consistently validate, requiring the selection of a user as well as allowing for only one selection.

The code:

public void supervisorEmployeeID_Changed(object sender, XmlEventArgs e)
{
     try
     {
          int supervisorCount = e.Site.SelectChildren(XPathNodeType.Element).Count;

          if (this.Errors.GetErrors("_supervisorCountError").Length > 0)
               this.Errors.Delete("_supervisorCountError");

          if (supervisorCount > 1)
               this.Errors.Add(e.Site, "_supervisorCountError", "You can only select one Manager");
          else if (supervisorCount < 1)
               this.Errors.Add(e.Site, "_supervisorCountError", "You must select a Manager");
     }
     catch { }
}

The above is meant to serve as a reference and should be self-explanatory.

Bookmark and Share
Leave a comment

1 Comments.

Leave a Reply


[ Ctrl + Enter ]

Performance Optimization WordPress Plugins by W3 EDGE