Add attribute - InfoPath Dev
in

InfoPath Dev

Add attribute

Last post 01-18-2007 01:11 PM by EricL. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 02-23-2006 07:26 PM

    • delu
    • Not Ranked
    • Joined on 01-12-2006
    • Posts 13

    Add attribute

    Hi there.

    I want to set a date picker to a date. I read I have to remove the nil attribute in order to do that. This works great, *but* the date picker is then set to can not be blank.
    How can I readd the attribute in case the user wants to remove the date?

    Thanks!
  • 02-23-2006 11:50 PM In reply to

    Hi Delu,
    Check out the jscript code in the samples that ship with InfoPath. They have the same issue and solve it in code.

    Patrick Halstead [InfoPath MVP]
    InfoPath Dev Seattle
    Patrick Halstead
    Project Manager at Qdabra
  • 02-24-2006 07:23 AM In reply to

    This might be helpful:

    /*------------------------------------------------------------------------------
    setNil() - Empty a nillable element.
    ------------------------------------------------------------------------------*/
    function setNil(xpath)
    {
    var xmlNode = getNode(xpath);

    if (!xmlNode || xmlNode.text === "")
    return;

    // Create xsi:nil attribute with the proper namespace.
    var xmlNil = xmlNode.ownerDocument.createNode(2, "xsi:nil", "http://www.w3.org/2001/XMLSchema-instance");
    xmlNil.text = "true";

    // The order is important.
    xmlNode.text = "";
    xmlNode.setAttributeNode(xmlNil);
    }


    ---------------
    Matt Faus
    InfoPath Dev Texas
    Matt Faus / Microsoft InfoPath MVP
    Qdabra® Software / Streamline data gathering to turn process into knowledge
  • 01-18-2007 01:11 PM In reply to

    • EricL
    • Not Ranked
    • Joined on 01-18-2007
    • Posts 5
    Hi,
    The posted code above was a great help. I transformed it into C# in a VS2003 project and thought it might be helpful:
    Thanks!

    // CUSTOM Method: SetNil
    // Needed because of the xml and form validation rules on certain fields like DateTime, Boolean, etc.
    public void SetNil(IXMLDOMNode node)
    {
    if( node.text == "")
    { return; }
    IXMLDOMElement nilElement;
    IXMLDOMAttribute nilAttribute;

    // Create an element and an attribute for xsi:nil with the proper namespace.
    nilElement = (IXMLDOMElement)node;
    nilAttribute = (IXMLDOMAttribute)node.ownerDocument.createNode((int)DOMNodeType.NODE_ATTRIBUTE,"xsi:nil",xsiNS);
    nilAttribute.text = "true";

    // The order is important
    node.text = String.Empty;
    nilElement.setAttributeNode(nilAttribute);
    }
Page 1 of 1 (4 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.