Prompt User to submit if Fields changed when they click button - InfoPath Dev
in

InfoPath Dev

Use our Google Custom Search for best site search results.

Prompt User to submit if Fields changed when they click button

Last post 01-24-2013 08:31 AM by jnava121. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 01-15-2013 10:18 AM

    Prompt User to submit if Fields changed when they click button

    Hi,   I have a close button , and if the form has changed , I want to prompt the user to Submit  ( instead of save) 

     

    Is there a way to do this with code? I've searched couldnt find anything.

  • 01-17-2013 10:13 PM In reply to

    Re: Prompt User to submit if Fields changed when they click button

    Here's one way to do it: The idea is to store a copy of the form fields & values immediately after opening, and then add a function to detect when the fields have changed. When the user clicks your close button, call this function and if the values have changed, add code to submit the form; if they haven't changed, add code to save the form instead.

    Here's some code to get you started. Everything in black is automatically generated by InfoPath if you make the right selections. To generate the Loading function, select Developer -> Load Event. To generate the close button function, right click on your button, then select Button Properties and then Edit Form Code.

    Once you've done that, just add the code in red. There might be other code and comments in-between the methods below that is automatically generated by InfoPath, just keep that in mind as you’re making your changes.


    namespace MyTemplateName

    {

    public partial class FormCode

    {

            // add a string to copy over the form fields & values immediately after loading

            string mainXml;

    }

     

    public void FormEvents_Loading(object sender, LoadingEventArgs e)
    {

                // store the fields & values from the main data source into our mainXml variable

    mainXml = this.MainDataSource.CreateNavigator().SelectSingleNode("/*").InnerXml;

    }

     

    // add a method to tell when any of the form fields have changed

                public bool HasFormChanged()

                 {

                            string currentXml = this.MainDataSource.CreateNavigator().SelectSingleNode("/*").InnerXml;

     

                            bool returnVal = !currentXml.Equals(mainXml, StringComparison.Ordinal);

     

                            return returnVal;

                 }

     

                public void MyCloseButtonName(object sender, ClickedEventArgs e)

                {

                           

                            if (HasFormChanged())

                            {

                                        // add code to submit the form, because it has changed

                            }

                            else

                            {

                                        // add code to save the form instead

                             }

     

                            // add code to close the form

    }

    }

     

    Jennifer Lindsay
    Qdabra® Software/InfoPathDev.com
    The InfoPath Experts – Streamline data gathering to turn process into knowledge.™

    Filed under: , , ,
  • 01-18-2013 08:39 AM In reply to

    Re: Prompt User to submit if Fields changed when they click button

    You could also check the form's IsDirty property.
    Hilary Stoupa

  • 01-24-2013 08:31 AM In reply to

    Re: Prompt User to submit if Fields changed when they click button

     Thanks for the replies both are very helpful and I can use both these solutions.

     





    How would I emulate the Default   Pop up box that ask if you want to submit before you close ?   

    show message then :

     if (MessageBox.Equals(DialogResult.OK))
                    {

     // Submit the form to SharePoint
    DataConnection spConn =
      DataConnections["SharePoint Library Submit"];
    spConn.Execute();
     

     


                    }

     

     

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