Default Fields - InfoPath Dev
in

InfoPath Dev

Default Fields

Last post 02-28-2006 06:56 AM by brandt. 2 replies.
Page 1 of 1 (3 items)
Sort Posts: Previous Next
  • 02-27-2006 11:46 AM

    • brandt
    • Top 500 Contributor
    • Joined on 02-23-2006
    • USA
    • Posts 26

    Default Fields

    I have noticed two different behavoirs with the form after you press submit:
    1) If all data is enterd manually-then the data remains on the form after a Submit
    2) Any fields that have been programmatically set default to a blank field afte pressing Submit.

    ???How to make the fields retain their data after Submit when the data is populated from a secondary data source???
  • 02-27-2006 10:51 PM In reply to

    How about just using a custom submit handler? Create a button and have it submit via a rule. Then it won't pass through the default submit handler. That might do the trick. If not, consider writing an OnSubmit handler to preserve and copy back the data.
    Patrick Halstead
    Project Manager at Qdabra
  • 02-28-2006 06:56 AM In reply to

    • brandt
    • Top 500 Contributor
    • Joined on 02-23-2006
    • USA
    • Posts 26
    I tried submnitting via a rule on a button and that exhibited the same behavoir...here is my code...could you show me how "to writing an OnSubmit handler to preserve and copy back the data"...you will see the fileds I populate via code below...thnx.




    /*
    * This file contains functions for data validation and form-level events.
    * Because the functions are referenced in the form definition (.xsf) file,
    * it is recommended that you do not modify the name of the function,
    * or the name and number of arguments.
    *
    */

    // The following line is created by Microsoft Office InfoPath to define the prefixes
    // for all the known namespaces in the main XML data file.
    // Any modification to the form files made outside of InfoPath
    // will not be automatically updated.
    //<namespacesDefinition>
    XDocument.DOM.setProperty("SelectionNamespaces", 'xmlns:q="http://schemas.microsoft.com/office/infopath/2003/ado/queryFields" xmlns:d="http://schemas.microsoft.com/office/infopath/2003/ado/dataFields" xmlns:dfs="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution" xmlns:my="http://schemas.microsoft.com/office/infopath/2003/myXSD/2006-02-24T18:16:36"');
    //</namespacesDefinition>


    //=======
    // The following function handler is created by Microsoft Office InfoPath.
    // Do not modify the name of the function, or the name and number of arguments.
    // This function is associated with the following field or group (XPath): /dfs:myFields/dfs:dataFields/d:tblRAHeader/@CustomerNum
    // Note: Information in this comment is not updated after the function handler is created.
    //=======
    function msoxd__tblRAHeader_CustName_attr::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.

    // Get the DOM for the Seconday Data Source
    var dat = XDocument.DataObjects("CustomerInfo").DOM;
    var ns = "xmlns:dfs='http://schemas.microsoft.com/office/infopath/2003/dataFormSolution' xmlns:d='http://schemas.microsoft.com/office/infopath/2003/ado/dataFields\'";
    dat.setProperty("SelectionNamespaces", ns);


    // Get the value of the selected item in the dropdown list
    var sVariable = getNodeValue("/dfs:myFields/dfs:dataFields/d:tblRAHeader/@CustName");

    // Get the node from the Seconday Data Source using the value from the dropdown list
    var xNode = dat.selectSingleNode("/dfs:myFields/dfs:dataFields/d:vwCustomerInfo_basic[@Name='" + sVariable + "']");

    // If the value is not null (shouldn't be but j.i.c.)
    if (xNode == null)
    {
    setNodeValue("/dfs:myFields/dfs:dataFields/d:tblRAHeader/@CustomerNum", "");
    setNodeValue("/dfs:myFields/dfs:dataFields/d:tblRAHeader/@CustAddr1", "");
    setNodeValue("/dfs:myFields/dfs:dataFields/d:tblRAHeader/@CustAddr2", "");
    setNodeValue("/dfs:myFields/dfs:dataFields/d:tblRAHeader/@CustAddr3", "");
    setNodeValue("/dfs:myFields/dfs:dataFields/d:tblRAHeader/@CustZIP", "");
    }
    else
    // Set the values in the form DOM using the values from the Seconday Data Source DOM
    {
    setNodeValue("/dfs:myFields/dfs:dataFields/d:tblRAHeader/@CustomerNum", xNode.selectSingleNode("@Customer").text);
    setNodeValue("/dfs:myFields/dfs:dataFields/d:tblRAHeader/@CustAddr1", xNode.selectSingleNode("@Address1").text);
    setNodeValue("/dfs:myFields/dfs:dataFields/d:tblRAHeader/@CustAddr2", xNode.selectSingleNode("@Address2").text);
    setNodeValue("/dfs:myFields/dfs:dataFields/d:tblRAHeader/@CustAddr3", xNode.selectSingleNode("@Address3").text);
    setNodeValue("/dfs:myFields/dfs:dataFields/d:tblRAHeader/@CustZIP", xNode.selectSingleNode("@Zip").text);
    }



    }


    /* =============================================================================
    Node value operations
    ============================================================================= */

    /*------------------------------------------------------------------------------
    isInvalidOrEmpty()
    ------------------------------------------------------------------------------*/
    function isInvalidOrEmpty(xmlNode)
    {
    // If there is no value, ignore it.
    if (!xmlNode || !xmlNode.text)
    return true;

    // The caller can pass additional error types as optional arguments.
    var aErrorTypes = new Array;
    if (arguments.length > 1)
    {
    for (var i=1; i<arguments.length; i++)
    aErrorTypes.push(arguments);
    }
    else
    {
    aErrorTypes.push("SCHEMA_VALIDATION");
    }

    // If there is a validation error related to this node,
    // then the node is invalid.
    for (var i=0; i<XDocument.Errors.Count; i++)
    {
    var oError = XDocument.Errors(i);

    if (xmlNode == oError.Node)
    {
    for (var j in aErrorTypes)
    {
    if (oError.Type == aErrorTypes[j])
    return true;
    }
    }
    }

    // Is valid (no error was found).
    return false;
    }


    /*------------------------------------------------------------------------------
    getNodeValue()
    ------------------------------------------------------------------------------*/
    function getNodeValue(xpath, defaultValue)
    {
    var xmlNode = getNode(xpath);

    if (isInvalidOrEmpty(xmlNode))
    return (arguments.length > 1) ? defaultValue : "";
    else
    return xmlNode.text;
    }

    /*------------------------------------------------------------------------------
    getNode()
    ------------------------------------------------------------------------------*/
    function getNode(xpath)
    {
    // Both XML node and absolute XPath are allowed.
    if (typeof(xpath) == "string")
    return XDocument.DOM.selectSingleNode(xpath);
    else
    return xpath;
    }

    /*------------------------------------------------------------------------------
    setNodeValue()
    ------------------------------------------------------------------------------*/
    function setNodeValue(xpath, value)
    {
    var xmlNode = getNode(xpath);

    if (!xmlNode)
    return;

    // Setting the value would mark the document as dirty.
    // Let's do that if the value has really changed.
    if (xmlNode.text != value)
    xmlNode.text = value;
    }

    //=======
    // The following function handler is created by Microsoft Office InfoPath.
    // Do not modify the name of the function, or the name and number of arguments.
    // This function is associated with the following field or group (XPath): /dfs:myFields/dfs:dataFields/d:tblRAHeader/@ShipToName
    // Note: Information in this comment is not updated after the function handler is created.
    //=======
    function msoxd__tblRAHeader_ShipToName_attr::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.
    // Get the DOM for the Seconday Data Source
    var dat = XDocument.DataObjects("ShipToInfo").DOM;
    var ns = "xmlns:dfs='http://schemas.microsoft.com/office/infopath/2003/dataFormSolution' xmlns:d='http://schemas.microsoft.com/office/infopath/2003/ado/dataFields\'";
    dat.setProperty("SelectionNamespaces", ns);


    // Get the value of the selected item in the dropdown list
    var sVariable = getNodeValue("/dfs:myFields/dfs:dataFields/d:tblRAHeader/@ShipToName");

    // Get the node from the Seconday Data Source using the value from the dropdown list
    var xNode = dat.selectSingleNode("/dfs:myFields/dfs:dataFields/d:vwShipToInfo_RA[@Name='" + sVariable + "']");

    // If the value is not null (shouldn't be but j.i.c.)
    if (xNode == null)
    {
    setNodeValue("/dfs:myFields/dfs:dataFields/d:tblRAHeader/@ShipToNum", "");
    setNodeValue("/dfs:myFields/dfs:dataFields/d:tblRAHeader/@ShipToAddr1", "");
    setNodeValue("/dfs:myFields/dfs:dataFields/d:tblRAHeader/@ShipToAddr2", "");
    setNodeValue("/dfs:myFields/dfs:dataFields/d:tblRAHeader/@ShipToAddr3", "");
    setNodeValue("/dfs:myFields/dfs:dataFields/d:tblRAHeader/@ShipToZIP", "");
    }
    else
    // Set the values in the form DOM using the values from the Seconday Data Source DOM
    {
    setNodeValue("/dfs:myFields/dfs:dataFields/d:tblRAHeader/@ShipToNum", xNode.selectSingleNode("@ShipTo").text);
    setNodeValue("/dfs:myFields/dfs:dataFields/d:tblRAHeader/@ShipToAddr1", xNode.selectSingleNode("@Address1").text);
    setNodeValue("/dfs:myFields/dfs:dataFields/d:tblRAHeader/@ShipToAddr2", xNode.selectSingleNode("@Address2").text);
    setNodeValue("/dfs:myFields/dfs:dataFields/d:tblRAHeader/@ShipToAddr3", xNode.selectSingleNode("@Address3").text);
    setNodeValue("/dfs:myFields/dfs:dataFields/d:tblRAHeader/@ShipToZIP", xNode.selectSingleNode("@Zip").text);
    }


    }


    //=======
    // The following function handler is created by Microsoft Office InfoPath.
    // Do not modify the name of the function, or the name and number of arguments.
    //=======
    function XDocument::OnSubmitRequest(eventObj)
    {
    // If the submit operation is successful, set
    // eventObj.ReturnStatus = true;
    // Write your code here
    }
Page 1 of 1 (3 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.