So, I am building a form that will write line items to a Task List. The form has multiple tabs and has a number of required fields. These required fields should be filled out prior to formal submission of the form. However, I need to be able to submit data back to SharePoint for these tasks regardless of the validation.
I found a great article here:
public void SaveAsDraftButton_Clicked(object sender, ClickedEventArgs e)
I had to make some changes to this for it to work in my scenario. I had to backup the errors prior to deleting them because they were valid.
So I had to do this:
public List<BackupFormError> BackupErrors(FormErrorCollection Errors)
List<BackupFormError> backupErrors = new List<BackupFormError>();
foreach (FormError formError in Errors)
BackupFormError backupError = new BackupFormError();
backupError.Context = formError.Site;
backupError.Name = formError.Name == String.Empty ? formError.Site.LocalName : formError.Name;
backupError.Message = formError.Message;
The Errors collection on the form is a static reference (I believe). The FormErrorsCollection is also an abstract type meaning I couldn't create a variable to hold the errors as a backup and then write them back. Instead, I created a basic inline object and added those objects to a Generic List.
It worked very well, with the exception that the .Name property of the Error was always blank. When creating a new FormError, it would throw an exception when the object was created with a blank .Name property.