Reset form on submit using jscript? - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

Reset form on submit using jscript?

Last post 09-12-2010 07:59 PM by ZhenYuan. 30 replies.
Page 1 of 3 (31 items) 1 2 3 Next >
Sort Posts: Previous Next
  • 09-01-2005 12:22 PM

    Reset form on submit using jscript?

    How can I reset a form after I click the "Submit" button? I would like my last line of code in my OnSubmitRequest to clear the form. I am using jscript for the code. Any help would be greatly appreciated.

    Thanks.
  • 09-01-2005 02:00 PM In reply to

    Re: Reset form on submit using jscript?

    Hi jaredhanks,
    Welcome to the Forum!
    Create a IXMLDomDocument from template.xml file and Replace the main dom root node with the root node from IXMLDomDocument. This will refresh all of the fields in your main dom.

    Hope this Helps!

    Agni
    InfoPath Dev India
  • 09-01-2005 02:11 PM In reply to

    Re: Reset form on submit using jscript?

    I am new to InfoPath and am I don't understand exactly what you mean.


    The following is the code for the OnSubmitRequest I have for the form...

    function XDocument::OnSubmitRequest(eventObj)
    {
    var iMsg = new ActiveXObject("CDO.Message");
    //dt = new Date();
    //day = dt.getDate();
    dowArray = new Array("Sunday", "Monday", "Tuesday", "Wednesday",
    "Thursday", "Friday", "Saturday");
    today = new Date();
    dow = today.getDay();
    day = (dowArray[dow] );

    iMsg.To = "rico-store@domain.com";
    iMsg.From = XDocument.DOM.selectSingleNode("//my:email").text;
    iMsg.Subject = XDocument.DOM.selectSingleNode("//my:StoreNumber").text + " - " + XDocument.DOM.selectSingleNode("//my:Subject").text;
    iMsg.TextBody += "StoreNumber="
    iMsg.TextBody += XDocument.DOM.selectSingleNode("//my:StoreNumber").text + "\n";
    iMsg.TextBody += "Contact="
    iMsg.TextBody += XDocument.DOM.selectSingleNode("//my:Contact").text + "\n";
    iMsg.TextBody += "Date="
    iMsg.TextBody += XDocument.DOM.selectSingleNode("//my:date").text + "\n";
    iMsg.TextBody += "Day="
    iMsg.TextBody += day + "\n";
    iMsg.TextBody += "StoreProblem="
    iMsg.TextBody += XDocument.DOM.selectSingleNode("//my:ProblemDescription").text + "\n";


    if (XDocument.DOM.selectSingleNode("//my:ProblemDescription").text == "Other")
    {
    iMsg.TextBody += "OtherProblem="
    iMsg.TextBody += XDocument.DOM.selectSingleNode("//my:OtherProblem").text + "\n";
    }

    else if (XDocument.DOM.selectSingleNode("//my:ProblemDescription").text == "Polling")
    {
    iMsg.TextBody += "PollingProblem="
    iMsg.TextBody += XDocument.DOM.selectSingleNode("//my:PollingProblem").text + "\n";
    iMsg.TextBody += "PollingOffender="
    iMsg.TextBody += XDocument.DOM.selectSingleNode("//my:PollingOffender").text + "\n";
    }

    if (XDocument.DOM.selectSingleNode("//my:TrainingRelated").text == "true" )
    {
    iMsg.TextBody += "TrainingRelated=Yes" + "\n";
    }

    else
    {
    iMsg.TextBody += "TrainingRelated=No" + "\n";
    }

    if (XDocument.DOM.selectSingleNode("//my:AutoResolve").text == "true" )
    {
    iMsg.TextBody += "AutoResolve=Yes" + "\n";
    }

    else
    {
    iMsg.TextBody += "AutoResolve=No" + "\n";
    }

    iMsg.TextBody += "Content="
    iMsg.TextBody += XDocument.DOM.selectSingleNode("//my:content").text + "\n";

    iMsg.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "mail.domain.com";
    // Use the SMTP over the netowrk for sending method

    iMsg.Configuration.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2;
    // Make persistent

    iMsg.Configuration.Fields.Update();

    iMsg.Send();
    XDocument.UI.Alert("Thanks for submitting your issue, you should receive an e-mail with your support ID soon");

    }


    I would like the last line of the code to clear the form to the original values.

    Any additional help is greatly appreciated.

    Thanks in advance.
  • 09-02-2005 01:03 PM In reply to

    Re: Reset form on submit using jscript?

    This is what he means...it is VBScript but you can get the point...

    '===========================
    Sub ReLoadForm()

    'load the template xml that is generated by the Designer
    Dim domTemplate
    Set domTemplate = CreateObject("MSXML2.DomDocument.5.0")

    domTemplate.async = false
    domTemplate.validateOnParse = false
    domTemplate.load("template.xml")

    If domTemplate Is Nothing Then

    XDocument.UI.Alert("Could not load the template!")

    Else

    'Get the ITT Node in the form's DOM
    Dim existingDataFields
    Set existingDataFields = XDocument.DOM.selectSingleNode("//my:Fields")
    Call domTemplate.setProperty("SelectionNamespaces", "xmlns:my=""http://schemas.microsoft.com/office/infopath/2003/myXSD/2005-07-21T20:40:37""")

    'Replace with node from loaded XML template.
    Dim newDataFields
    Set newDataFields = domTemplate.selectSingleNode("//my:Fields")
    Call existingDataFields.parentNode.replaceChild(newDataFields.cloneNode(true), existingDataFields)

    End If

    End Sub
    Jason
    http://www.k2distillery.com/
  • 09-02-2005 10:46 PM In reply to

    Re: Reset form on submit using jscript?

    Thanks for the reply vt_asparagus, its great to see many people answering in the Forums.


    Agni
    InfoPath Dev India
  • 06-23-2006 05:17 AM In reply to

    • sdecou
    • Not Ranked
    • Joined on 06-06-2006
    • USA
    • Posts 2

    Re: Reset form on submit using jscript?

    I am trying to get this code to run and I am using Visual Studio .NET. I need to know what everything should be dimmed as below:

    Sub ReLoadForm()

    'load the template xml that is generated by the Designer
    Dim domTemplate
    Set domTemplate = CreateObject("MSXML2.DomDocument.5.0")

    domTemplate.async = false
    domTemplate.validateOnParse = false
    domTemplate.load("template.xml")

    If domTemplate Is Nothing Then

    XDocument.UI.Alert("Could not load the template!")

    Else

    'Get the ITT Node in the form's DOM
    Dim existingDataFields
    Set existingDataFields = XDocument.DOM.selectSingleNode("//my:Fields")
    Call domTemplate.setProperty("SelectionNamespaces", "xmlns:my=""http://schemas.microsoft.com/office/infopath/2003/myXSD/2005-07-21T20:40:37""")

    'Replace with node from loaded XML template.
    Dim newDataFields
    Set newDataFields = domTemplate.selectSingleNode("//my:Fields")
    Call existingDataFields.parentNode.replaceChild(newDataFields.cloneNode(true), existingDataFields)

    End If

    End Sub
  • 08-10-2010 01:14 AM In reply to

    Re: Reset form on submit using jscript?

    Hi guys,

    I'm not a programmer and after spending one day reading through the forums, I still don't get it on how to add a "Reset" button for my form. I've tried copying some codes here and there but they usually crash my form. Does anyone has a code for a Reset button in VB? I just want to have a button where I click and fields in the selected sections of my form are emptied of previous values?

     I'm just about out of options and going to use rules to empty my 60+ form fields...

     

    Thanks for any help!

  • 08-10-2010 07:51 AM In reply to

    Re: Reset form on submit using jscript?

    If you use rules for 60 fields it risk to slow down your form. The best way is to put your 60 field in a group and reference this group to another reference node, and when you click on reset you clone your reference node and replace it by your current node. If you give me the Xpath of your reference and current node I can help you with that.

  • 08-10-2010 06:05 PM In reply to

    Re: Reset form on submit using jscript?

    Hi! Thanks for your help. My node with all the subgroups and fields is /my:myFields/my:Form_Container while the clone node I've just created is /my:myFields/my:Form_Clone.

    By the way, I'm trying to create a dynamic form which opens up optional sections as user fill up the form. It is done now but I have lots and lots and lots of rules. The rules hide fields that appear when the user choose to update fields and I also have a wide array of rules for read only and mandatory fields. And I am also pulling existing data from a database to populate many fields. As a result, my form really has quite alot of rules. Maybe 150 of them... Am I doing it wrong? I need the rules but as you said, the form is taking some time to load. Up to 15 seconds on first load (the very first time since I switched on my comp).

     Really appreciate you sharing your experience and advise. Thanks again!

  • 08-10-2010 08:01 PM In reply to

    Re: Reset form on submit using jscript?

    Hi Zhen Yuan, you have to clone the group form_container on the group form_clone and put this vbs code on the button:

    Dim oItem, oParent, oClone

    Set oItem = XDocument.DOM.selectSingleNode("/my:myFields/my:Form_Container")

    Set oClone = XDocument.DOM.selectSingleNode("/my:myFields/my:Form_Clone/my:Form_Container").cloneNode(true)

    Set oParent = oItem.parentNode

    oParent.replaceChild oClone, oItem

    If you had choose to modify by rules (on click), because you have to reinitialize the field one by one. It can take several second and if you add some field, you have to had rules.

    With this method, if you add some fied, you don't need to change anything, it suppose to work directly.

    I think that 15 seconds on the load is acceptable.

  • 08-11-2010 02:09 AM In reply to

    Re: Reset form on submit using jscript?

    Do I need to write something else to clone form_container first?

    I tried using the VBS code on my button but there were errrors. My code is:

    Public Sub CTRL281_Clicked(ByVal sender As Object, ByVal e As ClickedEventArgs)

    ' Write your code here.

    Dim oItem, oParent, oClone

    oItem = XDocument.DOM.selectSingleNode("/my:myFields/my:Form_Container")

    oClone = XDocument.DOM.selectSingleNode("/my:myFields/my:Form_Clone/my:Form_Container").cloneNode(True)

    oParent = oItem.parentNode

    oParent.replaceChild(oClone, oItem)

    End Sub

     

    And the errors say "Name 'XDcoument' is not declared".

    There are also warnings for "Variable declaration without an 'As' clause; type of object assumed" for the Dim oItem, oParent, oClone portion.

    Do I need to do some declaration? Sorry for my newbie programming level...

  • 08-11-2010 04:36 AM In reply to

    Re: Reset form on submit using jscript?

     Hi, zhenYuan can you attach your form?

  • 08-11-2010 05:58 PM In reply to

    Re: Reset form on submit using jscript?

    Hi,

    Sorry, I can't attach the original form as it contains sensitive information. How about I attach this clean form? I am trying to create a reset button with the button. However, through this, I realized that your code is for VB script while my form is in Visual Basic code :( Sorry for giving you wrong info previously.

  • 08-11-2010 06:20 PM In reply to

    Re: Reset form on submit using jscript?

     ok Zhen yuan, I update that fo VB:


    Dim oItem As XPathNavigator= Me.CreateNavigator().SelectSingleNode("/my:myFields/my:Form_Container", Me.NamespaceManager)
    Dim oClone As XPathNavigator= Me.CreateNavigator().SelectSingleNode("/my:myFields/my:Form_Clone/my:Form_Container", Me.NamespaceManager).Clone()
    oItem.ReplaceSelf(oClone)

    Hope it help :)

  • 08-11-2010 06:35 PM In reply to

    Re: Reset form on submit using jscript?

    Hi,

     Thanks! There are no compile errors now but when I try the button, a Null exception error is reported. The modified form is as attached. Am I still doing something wrong?

     

Page 1 of 3 (31 items) 1 2 3 Next >
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.