Finding view and setting focus - InfoPath Dev
in

InfoPath Dev

Finding view and setting focus

Last post 10-14-2005 11:26 AM by 4spammers. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 10-13-2005 08:15 AM

    Finding view and setting focus

    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.

    I can use View.SelectText() to set focus, but how can I tell which view(s) have a control bound to the node? Can this be answered using JScript?

    Here's some pseudocode to describe my question...

    // assume we're given XPath to a node with a "problem"
    var problemNodeXPath = "/xpath/to/node";

    // Fetch the specific DOM node using XPath
    var objNode = XDocument.DOM.selectSingleNode(problemNodeXPath);

    // Get the views that contain 1+ controls bound to the node
    // Can this be done using JScript?
    var possibleViews = viewsWithControlsBoundToNode(objNode);

    // Switch to the first view that uses the data
    XDocument.View.SwitchView(possibleViews(0))

    // Set focus to the "problem" node
    XDocument.View.SelectText(objNode);

    In the fictitious viewsWithControlsBoundToNode(node) 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 anyViewWithControlBoundToNode(node) method would suffice.

    My apologies if this has been covered or answered elsewhere. Any help would be appreciated.
  • 10-14-2005 08:45 AM In reply to

    Re: Finding view and setting focus

    Try this:

    var nodelist = XDocument.View.GetContextNodes();

    var present = false;

    while( n = nodelist.nextNode() )
    {
    if( n == selectSingleNode("xpath/to/node") )
    {
    present = true;
    break;
    }
    }

    if( present )
    XDocument.View.SelectText(objNode);



    ---------------
    Matt Faus
    Matt Faus / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 10-14-2005 11:26 AM In reply to

    Re: Finding view and setting focus

    Thanks Matt. Still not working for me.

    I'm not quite sure what XDocument.View.GetContextNodes() 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.

    I designed a new blank InfoPath form with two simple text nodes:

    Data Source
    myFields
    field1
    field2

    I then put one field (field1) onto the view along with a single button. Clicking on the button invokes XDocument.View.GetContextNodes() and displays the nodes and one level below (their children):

    function Button::OnClick(eventObj)
    {
    // fetch View's ContextNodes...whatever that means :o)
    var objXMLNodes = XDocument.View.GetContextNodes();

    for (var i = 0; i < objXMLNodes.Count; i++)
    {
    // fetch current node and its children
    var objNode = objXMLNodes.item(i);
    var objChildren = objNode.childNodes;

    // display current node's name
    XDocument.UI.Alert(objNode.nodeName);

    // display name of each child node
    for (var j = 0; j < objChildren.length; j++)
    {
    XDocument.UI.Alert(objChildren.item(j).nodeName);
    }
    }
    }

    XDocument.View.GetContextNodes() 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.

    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?
Page 1 of 1 (3 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.