In context with the ability to create forms, TX Text Control also provides the option to apply a specific behavior to form fields when one or more events occur. The sample illustrates the concept of such conditional instructions by deploying and previewing a form where the layout and behavior depends on predefined conditions.
The source code for this example is contained in the following directories:
By running this sample, a form is loaded that already contains conditional instructions that are listed in the overview of the Conditional Instructions sidebar. Each entry represents a set of actions to be performed when one or more conditions are fulfilled.
In order to deploy such a form, the content must be protected. This can be done by toggling both the Permissions tab's Fill in Form Fields and Read Only button before clicking Enforce Protection.
To preview the conditional instructions of a form, the sample provides a Preview button inside the Form Fields tab that is only enabled in case the Enabled Form Validation button is toggled. When clicking this button, the document becomes write-protected with the previous mentioned permissions settings. When untoggling the button, the content is reset to the state that was displayed before previewing the conditional instructions behavior.
On performing the preview mode, you can check the form behavior that is also described next to each form field. To show whether the defined form field content is valid, the Highlight Invalid Values button can be toggled.
To get an insight of creating conditional instructions, check out the article Creating Conditional Instructions for Form Fields.
To implement the preview behavior, it is necessary to store the current content and document permission settings before activating the preview mode. The content is saved to a byte array by using the TextControl.Save method. The DocumentPermissions.AllowEditingFormFields and DocumentPermissions.ReadOnly property values are stored to temporary bool variables.
To activate the preview, both document permissions variables are set to true and the TextControl.EditMode to ReadAndSelect.
private void ActivateCIPreview() {
// Store the current TextControl content.
m_txTextControl.Save(out m_rbtTextControlContent, BinaryStreamType.InternalUnicodeFormat);
// Store the current DocumentPermissions.AllowEditingFormFields and .ReadOnly property values.
m_bAllowEditinFormFieldsTemp = m_txTextControl.DocumentPermissions.AllowEditingFormFields;
m_bReadOnlyTemp = m_txTextControl.DocumentPermissions.ReadOnly;
// Set those document permissions that are necessary to show a preview.
m_txTextControl.DocumentPermissions.AllowEditingFormFields = true;
m_txTextControl.DocumentPermissions.ReadOnly = true;
// Hide all ribbon groups behind the TXITEM_FormValidationGroup group
for (int i = 3; i < m_rtRibbonFormFieldsTab.RibbonGroups.Count; i++) {
m_rtRibbonFormFieldsTab.RibbonGroups[i].Visible = false;
}
// Activate the preview by setting the TextControl.EditMode property value to
// EditMode.ReadAndSelect.
m_bIsPreviewActivated = true;
m_txTextControl.EditMode = EditMode.ReadAndSelect;
// Disable the TXITEM_EnableFormValidation ribbon toggle button
m_rbtnEnableFormValidation.Enabled = false;
}
Private Sub ActivateCIPreview()
' Store the current TextControl content.
m_txTextControl.Save(m_rbtTextControlContent, BinaryStreamType.InternalUnicodeFormat)
' Store the current DocumentPermissions.AllowEditingFormFields and .ReadOnly property values.
m_bAllowEditinFormFieldsTemp = m_txTextControl.DocumentPermissions.AllowEditingFormFields
m_bReadOnlyTemp = m_txTextControl.DocumentPermissions.ReadOnly
' Set those document permissions that are necessary to show a preview.
m_txTextControl.DocumentPermissions.AllowEditingFormFields = True
m_txTextControl.DocumentPermissions.ReadOnly = True
' Hide all ribbon groups behind the TXITEM_FormValidationGroup group
For i = 3 To m_rtRibbonFormFieldsTab.RibbonGroups.Count - 1
m_rtRibbonFormFieldsTab.RibbonGroups(i).Visible = False
Next
' Activate the preview by setting the TextControl.EditMode property value to
' EditMode.ReadAndSelect.
m_bIsPreviewActivated = True
m_txTextControl.EditMode = EditMode.ReadAndSelect
' Disable the TXITEM_EnableFormValidation ribbon toggle button
m_rbtnEnableFormValidation.Enabled = False
End Sub
When deactivating the preview, the saved content is reloaded by using the TextControl.Load method and the document permissions are reset to the values. An explicit resetting of the TextControl.EditMode property value to Edit is not necessary, because it is already set by loading the old content.
private void DeactivateCIPreview(bool reloadContent) {
// Reset the preview button checked state
m_rtbtnPreviewConditionalInstructions.Checked = false;
m_bIsPreviewActivated = false;
// Enable the "Enable Form Validation" button.
m_rbtnEnableFormValidation.Enabled = true;
// Reset the Textcontrol content and permissions.
if (reloadContent) {
// Reload the Textcontrol content.
m_txTextControl.Load(m_rbtTextControlContent, BinaryStreamType.InternalUnicodeFormat);
m_rbtTextControlContent = null;
// Reset the DocumentPermissions.AllowEditingFormFields and .ReadOnly property values.
m_txTextControl.DocumentPermissions.AllowEditingFormFields = m_bAllowEditinFormFieldsTemp;
m_txTextControl.DocumentPermissions.ReadOnly = m_bReadOnlyTemp;
}
}
Private Sub DeactivateCIPreview(ByVal reloadContent As Boolean)
' Reset the preview button checked state
m_rtbtnPreviewConditionalInstructions.Checked = False
m_bIsPreviewActivated = False
' Enable the "Enable Form Validation" button.
m_rbtnEnableFormValidation.Enabled = True
' Reset the Textcontrol content and permissions.
If reloadContent Then
' Reload the Textcontrol content.
m_txTextControl.Load(m_rbtTextControlContent, BinaryStreamType.InternalUnicodeFormat)
m_rbtTextControlContent = Nothing
' Reset the DocumentPermissions.AllowEditingFormFields and .ReadOnly property values.
m_txTextControl.DocumentPermissions.AllowEditingFormFields = m_bAllowEditinFormFieldsTemp
m_txTextControl.DocumentPermissions.ReadOnly = m_bReadOnlyTemp
End If
End Sub