<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://www.infopathdev.com:443/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Code</title><link>https://www.infopathdev.com:443/forums/45.aspx</link><description /><dc:language>en</dc:language><generator>CommunityServer 2007 SP3 (Build: 31118.962)</generator><item><title>Re: Finding view and setting focus</title><link>https://www.infopathdev.com:443/forums/thread/13802.aspx</link><pubDate>Fri, 14 Oct 2005 18:26:57 GMT</pubDate><guid isPermaLink="false">033a2e2d-04e2-4a9d-be01-a4634161eefd:13802</guid><dc:creator>4spammers</dc:creator><slash:comments>0</slash:comments><comments>https://www.infopathdev.com:443/forums/thread/13802.aspx</comments><wfw:commentRss>https://www.infopathdev.com:443/forums/commentrss.aspx?SectionID=45&amp;PostID=13802</wfw:commentRss><description>Thanks Matt. Still not working for me.&lt;br /&gt;&lt;br /&gt;I'm not quite sure what &lt;i&gt;XDocument.View.GetContextNodes()&lt;/i&gt; is supposed to be returning.  I was hoping that it was the subset of data nodes bound to the View...but it doesn't seem to be.&lt;br /&gt;&lt;br /&gt;I designed a new blank InfoPath form with two simple text nodes:&lt;br /&gt;&lt;br /&gt;&lt;u&gt;Data Source&lt;/u&gt;&lt;br /&gt; &lt;b&gt;myFields&lt;/b&gt;&lt;br /&gt;    &lt;b&gt;field1&lt;/b&gt;&lt;br /&gt;    &lt;b&gt;field2&lt;/b&gt;&lt;br /&gt;&lt;br /&gt;I then put one field (&lt;i&gt;field1&lt;/i&gt;) onto the view along with a single button.  Clicking on the button invokes &lt;i&gt;XDocument.View.GetContextNodes()&lt;/i&gt; and displays the nodes and one level below (their children):&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;function Button::OnClick(eventObj)&lt;br /&gt;{&lt;br /&gt;  // fetch View's ContextNodes...whatever that means :o)&lt;br /&gt;  var objXMLNodes = XDocument.View.GetContextNodes();&lt;br /&gt;&lt;br /&gt;  for (var i = 0; i &amp;lt; objXMLNodes.Count; i++)&lt;br /&gt;  {&lt;br /&gt;    // fetch current node and its children&lt;br /&gt;    var objNode = objXMLNodes.item(i);&lt;br /&gt;    var objChildren = objNode.childNodes;&lt;br /&gt;&lt;br /&gt;    // display current node's name&lt;br /&gt;    XDocument.UI.Alert(objNode.nodeName);&lt;br /&gt;&lt;br /&gt;    // display name of each child node&lt;br /&gt;    for (var j = 0; j &amp;lt; objChildren.length; j++)&lt;br /&gt;    {&lt;br /&gt;      XDocument.UI.Alert(objChildren.item(j).nodeName);&lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;i&gt;XDocument.View.GetContextNodes()&lt;/i&gt; returns one node: "my:myFields".  As it loops through the children of this node, it displays both "my:field1" and "my:field2", even though only the first of these is in the active view.&lt;br /&gt;&lt;br /&gt;Does anybody know how to enumerate the nodes bound to a View?  Or enumerate the controls in a view and find the bound data node for each control?</description></item><item><title>Re: Finding view and setting focus</title><link>https://www.infopathdev.com:443/forums/thread/13801.aspx</link><pubDate>Fri, 14 Oct 2005 15:45:17 GMT</pubDate><guid isPermaLink="false">033a2e2d-04e2-4a9d-be01-a4634161eefd:13801</guid><dc:creator>Matt Faus</dc:creator><slash:comments>0</slash:comments><comments>https://www.infopathdev.com:443/forums/thread/13801.aspx</comments><wfw:commentRss>https://www.infopathdev.com:443/forums/commentrss.aspx?SectionID=45&amp;PostID=13801</wfw:commentRss><description>Try this:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;var nodelist = XDocument.View.GetContextNodes();&lt;br /&gt;&lt;br /&gt;var present = false;&lt;br /&gt;&lt;br /&gt;while( n = nodelist.nextNode() )&lt;br /&gt;{&lt;br /&gt;	if( n == selectSingleNode("xpath/to/node") )&lt;br /&gt;	{&lt;br /&gt;		present = true;&lt;br /&gt;		break;&lt;br /&gt;	}&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;if( present )&lt;br /&gt;	XDocument.View.SelectText(objNode);&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;---------------&lt;br /&gt;Matt Faus&lt;br /&gt;</description></item><item><title>Finding view and setting focus</title><link>https://www.infopathdev.com:443/forums/thread/12625.aspx</link><pubDate>Thu, 13 Oct 2005 15:15:34 GMT</pubDate><guid isPermaLink="false">033a2e2d-04e2-4a9d-be01-a4634161eefd:12625</guid><dc:creator>4spammers</dc:creator><slash:comments>0</slash:comments><comments>https://www.infopathdev.com:443/forums/thread/12625.aspx</comments><wfw:commentRss>https://www.infopathdev.com:443/forums/commentrss.aspx?SectionID=45&amp;PostID=12625</wfw:commentRss><description>I am working with an InfoPath form with multiple views and submitting via HTTP POST to a Java servlet.  If I get an error message back from the servlet (e.g., the value for "/xpath/to/node" needs attention), I would like to not only display a message (I've done that), but also set focus to a field bound to that node.&lt;br /&gt;&lt;br /&gt;I can use &lt;i&gt;View.SelectText()&lt;/i&gt; to set focus, but how can I tell which view(s) have a control bound to the node?  Can this be answered using JScript?&lt;br /&gt;&lt;br /&gt;Here's some pseudocode to describe my question...&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;// assume we're given XPath to a node with a "problem"&lt;br /&gt;var problemNodeXPath = "/xpath/to/node";&lt;br /&gt;&lt;br /&gt;// Fetch the specific DOM node using XPath&lt;br /&gt;var objNode = XDocument.DOM.selectSingleNode(problemNodeXPath);&lt;br /&gt;&lt;br /&gt;// Get the views that contain 1+ controls bound to the node&lt;br /&gt;// Can this be done using JScript?&lt;br /&gt;var possibleViews = viewsWithControlsBoundToNode(objNode);&lt;br /&gt;&lt;br /&gt;// Switch to the first view that uses the data&lt;br /&gt;XDocument.View.SwitchView(possibleViews(0))&lt;br /&gt;&lt;br /&gt;// Set focus to the "problem" node&lt;br /&gt;XDocument.View.SelectText(objNode);&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;In the fictitious &lt;i&gt;viewsWithControlsBoundToNode(node)&lt;/i&gt; method above, I would iterate through available views, test each one to see if it contained a control bound to the given node, and return a list of those views that met the criteria.  Even an &lt;i&gt;anyViewWithControlBoundToNode(node)&lt;/i&gt; method would suffice.&lt;br /&gt;&lt;br /&gt;My apologies if this has been covered or answered elsewhere.  Any help would be appreciated.</description></item></channel></rss>