Problem: You want to be able to submit an InfoPath form despite any data validation errors that the form may have, so you want to ignore and delete all validation errors before submitting the form.
You can use the DeleteAll() method of the Errors collection to clear all of the errors in a form:
To Ignore and clear all of the errors in a form before submitting the form:
1 - Create a new form template
2 - Add a Textbox control to the view nad make it a required field by selecting its Cannot Be Blank Property.
3 - Go to the Submit Option under File and select "Allow users to submit this form" check box, select the "Perform custom action code option, deselect the "Show the Submit button in both the ribbon and the info tab in the InfoPath Filler". Click on Edit Code.
4 - Add following code to the FormEvents_Submit() event handler
Public Sub FormEvents_Submit(ByVal sender As Object, ByVal e As SubmitEventArgs)
' If the submit operation is successful, set
' e.CancelableArgs.Cancel = False
' Write your code here.
System.IO.File.WriteAllText("C:\Temp\myform.xml", MainDataSource.CreateNavigator().OuterXml)
e.CancelableArgs.Cancel = False
End Sub
You will need to give the form full trust in order to save it to disk
5 - Add a button control to the view and label it "Submit". Add the following code to the clicked event handler of this button
Public Sub CTRL2_5_Clicked(ByVal sender As Object, ByVal e As ClickedEventArgs)
' Write your code here.
If Me.Errors.Count > 0 Then
Me.Errors.DeleteAll()
End If
Submit()
End Sub
* The first three lines of code delete all of the errors that are in the Errors collection of the form, and the fourth line of code calls the FormEvents_Submit() event handler to submit the form.
6 - Save and build project
7 - Preview the form.
When the form opens, a red asterisk (*) should appear in the text box as an indication that it is a require field. Click the button. The form should be submitted without warning you about any data validation errors.
No comments:
Post a Comment