Howto: Deploy and Validate Forms

This chapter shows how to deploy created form documents using a Windows Forms UI that helps users to complete and validate form fields. This sample uses the same sample form template that is discussed in the technical article Creating Conditional Instructions for Form Fields.

The source code for this example is contained in the following directories:

  • %USERPROFILE%\Documents\TX Text Control 29.0.NET for Windows Forms\Samples\WinForms\VB.NET\FormFields\FormField_DeployNValidate
  • %USERPROFILE%\Documents\TX Text Control 29.0.NET for Windows Forms\Samples\WinForms\CSharp\FormFields\FormField_DeployNValidate

Used TX Text Control controls:

  • TXTextControl.TextControl

Relevant API links:

Creating a Read-Only Form Completion UI

In order to deploy a form, TX Text Control provides a special read-only mode for end-users to complete form fields. In this edit mode, content is read-only and form fields can be completed by end-users. Additionally, the form field logic in form of the connected conditional instructions is applied and executed.

Image

In order to switch to this form completion mode, the AllowEditingFormFields property and the Read Only property must be set to true and the TextControl.EditMode property needs to be set to EditMode.ReadAndSelect.

private void EnableFormFieldsProtection() {
 textControl.DocumentPermissions.ReadOnly = true;
 textControl.DocumentPermissions.AllowEditingFormFields = true;
 textControl.EditMode = TXTextControl.EditMode.ReadAndSelect;
}
Private Sub EnableFormFieldsProtection()
 TextControl.DocumentPermissions.ReadOnly = True
 TextControl.DocumentPermissions.AllowEditingFormFields = True
 TextControl.EditMode = TXTextControl.EditMode.ReadAndSelect
End Sub

On initializing TextControl, the existing form field ribbon tab is customized by removing groups that are built for the form creation process. Only the groups to highlight the form fields and to highlight the invalid values are kept. Additionally, a new ribbon group is added to validate and finish the form completion.

The following code shows the Form Load event that is used to load the form template, customize the ribbon and to switch to the read-only form completion mode:

private void Form1_Load(object sender, EventArgs e) {
 CustomizeFormFieldsTab(ribbonFormFieldsTab);
 ribbon.HasApplicationMenu = false;
 textControl.Load("travel-form.tx", StreamType.InternalUnicodeFormat);
 (ribbonFormFieldsTab.FindItem(
    RibbonFormFieldsTab.RibbonItem.TXITEM_HighlightInvalidValues) as RibbonToggleButton).Checked = true;

 EnableFormFieldsProtection();
}
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
 CustomizeFormFieldsTab(RibbonFormFieldsTab)
 ribbon.HasApplicationMenu = False
 TextControl.Load("travel-form.tx", StreamType.InternalUnicodeFormat)
 Dim btnHighlightInvalidValues As RibbonToggleButton =
     RibbonFormFieldsTab.FindItem(RibbonFormFieldsTab.RibbonItem.TXITEM_HighlightInvalidValues)
 btnHighlightInvalidValues.Checked = True

 EnableFormFieldsProtection()
End Sub

After starting the application, invalid fields are highlighted in yellow. When clicking the Validate Document button at this time, a message box warning is opened explaining that the document is not valid according to the conditional instruction rules.

Image

The following code shows how to iterate through the fields to check the validity of the conditional instructions:

foreach (FormField ff in textControl.FormFields) {
 if (!textControl.FormFields.ConditionalInstructions.HasValidValue(ff)) {
     MessageBox.Show(this, Resources.MSG_INVALIDDOCUMENT_TEXT,
         Resources.MSG_VALIDATIONFINISHED_CAPTION,
         MessageBoxButtons.OK,
         MessageBoxIcon.Warning);
     ff.ScrollTo();
     return;
 }
}
For Each ff As FormField In textControl.FormFields
 If (Not textControl.FormFields.ConditionalInstructions.HasValidValue(ff)) Then
     MessageBox.Show(Me, My.Resources.MSG_INVALIDDOCUMENT_TEXT, My.Resources.MSG_VALIDATIONFINISHED_CAPTION)
     ff.ScrollTo()
     Exit Sub
 End If
Next

MessageBox.Show(Me, My.Resources.MSG_VALIDDOCUMENT_TEXT, My.Resources.MSG_VALIDATIONFINISHED_CAPTION)

In case, all conditional instruction rules are fulfilled and the document is valid, a positive message box informs the user about this state.

Image