Clear all values from fields - InfoPath Dev
in

InfoPath Dev

Clear all values from fields

Last post 09-18-2009 07:58 AM by xfields. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 03-19-2008 09:58 AM

    Clear all values from fields

     Hi all,

     I have an issue I need fixing. I wanted to clear all values in fields when the user clicks a button so I altered code (jscript) from this forum (http://www.infopathdev.com/forums/p/5914/22037.aspx#22037) to help me out as follows:

    var objSource = XDocument.DOM.selectNodes("/dfs:myFields/dfs:dataFields/d:Training_Tool");
    objSource.removeAll();

    The problem is everytime this operation occurs it disables all my controls. This person had a similar problem (http://www.infopathdev.com/forums/p/6005/22452.aspx#22452). I tried altering my code accordingly however no luck. They are using 'IXMLDOMS' and, while not being a good programmer, I don't quite know how to implement that or if it even applies to my situation.

    I have too many nodes to manually set each to blank (i.e. XDocument.DOM.selectSingleNode("dfs:myFields/dfs:dataFields/d:Training_Tool/@OverallStatus").text = "";).

     Any ideas?

  • 03-19-2008 10:51 AM In reply to

    Re: Clear all values from fields

    The easy trick for this is to requery your main data source with a value that is not present(does not return any results).  Then it will return blank values in your data fields, except for any defaults.

    So query where ID = 99999 or whatever and that effectively resets all the fields and new data can be added just like a new record.

  • 03-21-2008 08:59 AM In reply to

    Re: Clear all values from fields

     

    I seem to have reached a point in my form that whenever I query a result that is not present, it disables the controls of all the dataFields in that connection. Is this normal?

     As a result, the removeAll() method and the query method (eg. ID = 99999) lead to the same situation, the fields become blocked and I am unable to enter back any information.

  • 03-21-2008 09:23 AM In reply to

    Re: Clear all values from fields

    No that is not normal with a database type form, where the DFS datafields are present.

    Depending on code, field validation, or possibly other corruption could maybe cause this.

    When you open a new form, they should be blank and allow input. Is this the case?

    You can always create a test form, with the query and data fields exposed and test the query with a blank results with that.

  • 09-18-2009 07:58 AM In reply to

    • xfields
    • Not Ranked
      Male
    • Joined on 09-08-2009
    • Germany
    • Posts 20

    Re: Clear all values from fields

    Dont realy understand the trick with the main datadource

    But....for me works the following code:

    public void clearForm_OnClick(DocActionEvent e)

    {

    IXMLDOMNodeList nodes = thisXDocument.DOM.selectNodes("//*");

    IXMLDOMNode node = nodes.nextNode();while (node != null)

    {

    if (node.selectNodes("child::*").length == 0)

    {

    try

    {

    node.text =
    "";

    }

    catch (Exception nodeNoTextEx)

    { }

    }

    try

    {

    node = nodes.nextNode();

    }

    catch (Exception nodeNotExsistEx)

    {

    node =
    null;

    }

    }

    }

    }

    This get all the nodes out of the dom and set the text-attribute to "" as long as there is a node.

    If u use for example the hungry notation for the naming or just use the default u can easyly select some sub volume/area like only groups or fields or or or

Page 1 of 1 (5 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.