Aspose::Words::Fields::FormField Class Reference

Detailed Description

Represents a single form field.

Microsoft Word provides the following form fields: checkbox, text input and dropdown (combobox).

FormField is an inline-node and can only be a child of Paragraph.

FormField is represented in a document by a special character and positioned as a character within a line of text.

A complete form field in a Word document is a complex structure represented by several nodes: field start, field code such as FORMTEXT, form field data, field separator, field result, field end and a bookmark. To programmatically create form fields in a Word document use DocumentBuilder.InsertCheckBox, DocumentBuilder.InsertTextInput and DocumentBuilder.InsertComboBox which make sure all of the form field nodes are created in a correct order and in a suitable state.

Examples

Shows how to insert a combo box.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
builder->Write(u"Please select a fruit: ");
// Insert a combo box which will allow a user to choose an option from a collection of strings.
SharedPtr<FormField> comboBox = builder->InsertComboBox(u"MyComboBox", MakeArray<String>({u"Apple", u"Banana", u"Cherry"}), 0);
ASSERT_EQ(u"MyComboBox", comboBox->get_Name());
ASSERT_EQ(FieldType::FieldFormDropDown, comboBox->get_Type());
ASSERT_EQ(u"Apple", comboBox->get_Result());
// The form field will appear in the form of a "select" html tag.
doc->Save(ArtifactsDir + u"FormFields.Create.html");

Shows how to formatting the entire FormField, including the field value.

auto doc = MakeObject<Document>(MyDir + u"Form fields.docx");
SharedPtr<FormField> formField = doc->get_Range()->get_FormFields()->idx_get(0);
formField->get_Font()->set_Bold(true);
formField->get_Font()->set_Size(24);
formField->get_Font()->set_Color(System::Drawing::Color::get_Red());
formField->set_Result(u"Aspose.FormField");
doc = DocumentHelper::SaveOpen(doc);
SharedPtr<Run> formFieldRun = doc->get_FirstSection()->get_Body()->get_FirstParagraph()->get_Runs()->idx_get(1);
ASSERT_EQ(u"Aspose.FormField", formFieldRun->get_Text());
ASPOSE_ASSERT_EQ(true, formFieldRun->get_Font()->get_Bold());
ASPOSE_ASSERT_EQ(24, formFieldRun->get_Font()->get_Size());
ASSERT_EQ(System::Drawing::Color::get_Red().ToArgb(), formFieldRun->get_Font()->get_Color().ToArgb());

#include <Aspose.Words.Cpp/Fields/FormField.h>

+ Inheritance diagram for Aspose::Words::Fields::FormField:

Public Member Functions

bool Accept (SharedPtr< DocumentVisitor > visitor) override
 Accepts a visitor. More...
 
bool get_CalculateOnExit ()
 True if references to the specified form field are automatically updated whenever the field is exited. More...
 
double get_CheckBoxSize ()
 Gets or sets the size of the checkbox in points. Has effect only when IsCheckBoxExactSize is true. More...
 
bool get_Checked ()
 Gets or sets the checked status of the check box form field. Default value for this property is false. More...
 
bool get_Default ()
 Gets or sets the default value of the check box form field. Default value for this property is false. More...
 
SharedPtr< DropDownItemCollectionget_DropDownItems ()
 Provides access to the items of a dropdown form field. More...
 
int32_t get_DropDownSelectedIndex ()
 Gets or sets the index specifying the currently selected item in a dropdown form field. More...
 
bool get_Enabled ()
 True if a form field is enabled. More...
 
String get_EntryMacro ()
 Returns or sets an entry macro name for the form field. More...
 
String get_ExitMacro ()
 Returns or sets an exit macro name for the form field. More...
 
String get_HelpText ()
 Returns or sets the text that's displayed in a message box when the form field has the focus and the user presses F1. More...
 
bool get_IsCheckBoxExactSize ()
 Gets or sets the boolean value that indicates whether the size of the textbox is automatic or specified explicitly. More...
 
int32_t get_MaxLength ()
 Maximum length for the text field. Zero when the length is not limited. More...
 
String get_Name ()
 Gets or sets the form field name. More...
 
NodeType get_NodeType () const override
 Returns NodeType.FormField. More...
 
bool get_OwnHelp ()
 Specifies the source of the text that's displayed in a message box when a form field has the focus and the user presses F1. More...
 
bool get_OwnStatus ()
 Specifies the source of the text that's displayed in the status bar when a form field has the focus. More...
 
String get_Result ()
 Gets or sets a string that represents the result of this form field. More...
 
String get_StatusText ()
 Returns or sets the text that's displayed in the status bar when a form field has the focus. More...
 
String get_TextInputDefault ()
 Gets or sets the default string or a calculation expression of a text form field. More...
 
String get_TextInputFormat ()
 Returns or sets the text formatting for a text form field. More...
 
TextFormFieldType get_TextInputType ()
 Gets or sets the type of a text form field. More...
 
FieldType get_Type ()
 Returns the form field type. More...
 
virtual const TypeInfoGetType () const override
 
virtual bool Is (const TypeInfo &target) const override
 
void RemoveField ()
 Removes the complete form field, not just the form field special character. More...
 
void set_CalculateOnExit (bool value)
 Setter for get_CalculateOnExit. More...
 
void set_CheckBoxSize (double value)
 Setter for get_CheckBoxSize. More...
 
void set_Checked (bool value)
 Setter for get_Checked. More...
 
void set_Default (bool value)
 Setter for get_Default. More...
 
void set_DropDownSelectedIndex (int32_t value)
 Setter for get_DropDownSelectedIndex. More...
 
void set_Enabled (bool value)
 Setter for get_Enabled. More...
 
void set_EntryMacro (const String &value)
 Setter for get_EntryMacro. More...
 
void set_ExitMacro (const String &value)
 Setter for get_ExitMacro. More...
 
void set_HelpText (const String &value)
 Setter for get_HelpText. More...
 
void set_IsCheckBoxExactSize (bool value)
 Setter for get_IsCheckBoxExactSize. More...
 
void set_MaxLength (int32_t value)
 Setter for get_MaxLength. More...
 
void set_Name (const String &value)
 Setter for get_Name. More...
 
void set_OwnHelp (bool value)
 Setter for get_OwnHelp. More...
 
void set_OwnStatus (bool value)
 Setter for get_OwnStatus. More...
 
void set_Result (const String &value)
 Setter for get_Result. More...
 
void set_StatusText (const String &value)
 Setter for get_StatusText. More...
 
void set_TextInputDefault (const String &value)
 Setter for get_TextInputDefault. More...
 
void set_TextInputFormat (const String &value)
 Setter for get_TextInputFormat. More...
 
void set_TextInputType (TextFormFieldType value)
 Setter for get_TextInputType. More...
 
void SetTextInputValue (const SharedPtr< Object > &newValue)
 Applies the text format specified in TextInputFormat and stores the value in Result. More...
 
- Public Member Functions inherited from SpecialChar
bool Accept (SharedPtr< DocumentVisitor > visitor) override
 Accepts a visitor. More...
 
NodeType get_NodeType () const override
 Returns NodeType.SpecialChar. More...
 
String GetText () override
 Gets the special character that this node represents. More...
 
- Public Member Functions inherited from Inline
SharedPtr< Fontget_Font ()
 Provides access to the font formatting of this object. More...
 
bool get_IsDeleteRevision ()
 Returns true if this object was deleted in Microsoft Word while change tracking was enabled. More...
 
bool get_IsFormatRevision ()
 Returns true if formatting of the object was changed in Microsoft Word while change tracking was enabled. More...
 
bool get_IsInsertRevision ()
 Returns true if this object was inserted in Microsoft Word while change tracking was enabled. More...
 
bool get_IsMoveFromRevision ()
 Returns true if this object was moved (deleted) in Microsoft Word while change tracking was enabled. More...
 
bool get_IsMoveToRevision ()
 Returns true if this object was moved (inserted) in Microsoft Word while change tracking was enabled. More...
 
SharedPtr< Paragraphget_ParentParagraph ()
 Retrieves the parent Paragraph of this node. More...
 
- Public Member Functions inherited from Node
SharedPtr< NodeClone (bool isCloneChildren)
 Creates a duplicate of the node. More...
 
int32_t get_CustomNodeId () const
 Specifies custom node identifier. More...
 
virtual SharedPtr< DocumentBaseget_Document () const
 Gets the document to which this node belongs. More...
 
virtual bool get_IsComposite ()
 Returns true if this node can contain other nodes. More...
 
SharedPtr< Nodeget_NextSibling ()
 Gets the node immediately following this node. More...
 
SharedPtr< CompositeNodeget_ParentNode ()
 Gets the immediate parent of this node. More...
 
SharedPtr< Nodeget_PreviousSibling ()
 Gets the node immediately preceding this node. More...
 
SharedPtr< Rangeget_Range ()
 Returns a Range object that represents the portion of a document that is contained in this node. More...
 
SharedPtr< CompositeNodeGetAncestor (NodeType ancestorType)
 Gets the first ancestor of the specified NodeType. More...
 
template<typename T >
GetAncestorOf ()
 
SharedPtr< NodeNextPreOrder (const SharedPtr< Node > &rootNode)
 Gets next node according to the pre-order tree traversal algorithm. More...
 
SharedPtr< NodePreviousPreOrder (const SharedPtr< Node > &rootNode)
 Gets the previous node according to the pre-order tree traversal algorithm. More...
 
void Remove ()
 Removes itself from the parent. More...
 
void set_CustomNodeId (int32_t value)
 Setter for get_CustomNodeId. More...
 
String ToString (SaveFormat saveFormat)
 Exports the content of the node into a string in the specified format. More...
 
String ToString (const SharedPtr< SaveOptions > &saveOptions)
 Exports the content of the node into a string using the specified save options. More...
 

Static Public Member Functions

static const TypeInfoType ()
 
- Static Public Member Functions inherited from SpecialChar
static const TypeInfoType ()
 
- Static Public Member Functions inherited from Inline
static const TypeInfoType ()
 
- Static Public Member Functions inherited from Node
static String NodeTypeToString (NodeType nodeType)
 A utility method that converts a node type enum value into a user friendly string. More...
 
static const TypeInfoType ()
 

Member Function Documentation

◆ Accept()

bool Aspose::Words::Fields::FormField::Accept ( System::SharedPtr< Aspose::Words::DocumentVisitor visitor)
overridevirtual

Accepts a visitor.

Calls DocumentVisitor.VisitFormField.

For more info see the Visitor design pattern.

Parameters
visitorThe visitor that will visit the node.
Returns
False if the visitor requested the enumeration to stop.
Examples

Shows how insert different kinds of form fields into a document, and process them with using a document visitor implementation.

void Visitor()
{
auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Use a document builder to insert a combo box.
builder->Write(u"Choose a value from this combo box: ");
SharedPtr<FormField> comboBox = builder->InsertComboBox(u"MyComboBox", MakeArray<String>({u"One", u"Two", u"Three"}), 0);
comboBox->set_CalculateOnExit(true);
ASSERT_EQ(3, comboBox->get_DropDownItems()->get_Count());
ASSERT_EQ(0, comboBox->get_DropDownSelectedIndex());
ASSERT_TRUE(comboBox->get_Enabled());
builder->InsertBreak(BreakType::ParagraphBreak);
// Use a document builder to insert a check box.
builder->Write(u"Click this check box to tick/untick it: ");
SharedPtr<FormField> checkBox = builder->InsertCheckBox(u"MyCheckBox", false, 50);
checkBox->set_IsCheckBoxExactSize(true);
checkBox->set_HelpText(u"Right click to check this box");
checkBox->set_OwnHelp(true);
checkBox->set_StatusText(u"Checkbox status text");
checkBox->set_OwnStatus(true);
ASPOSE_ASSERT_EQ(50.0, checkBox->get_CheckBoxSize());
ASSERT_FALSE(checkBox->get_Checked());
ASSERT_FALSE(checkBox->get_Default());
builder->InsertBreak(BreakType::ParagraphBreak);
// Use a document builder to insert text input form field.
builder->Write(u"Enter text here: ");
SharedPtr<FormField> textInput = builder->InsertTextInput(u"MyTextInput", TextFormFieldType::Regular, u"", u"Placeholder text", 50);
textInput->set_EntryMacro(u"EntryMacro");
textInput->set_ExitMacro(u"ExitMacro");
textInput->set_TextInputDefault(u"Regular");
textInput->set_TextInputFormat(u"FIRST CAPITAL");
textInput->SetTextInputValue(System::ObjectExt::Box<String>(u"New placeholder text"));
ASSERT_EQ(TextFormFieldType::Regular, textInput->get_TextInputType());
ASSERT_EQ(50, textInput->get_MaxLength());
// This collection contains all our form fields.
SharedPtr<FormFieldCollection> formFields = doc->get_Range()->get_FormFields();
ASSERT_EQ(3, formFields->get_Count());
// Fields display our form fields. We can see their field codes by opening this document
// in Microsoft and pressing Alt + F9. These fields have no switches,
// and members of the FormField object fully govern their form fields' content.
ASSERT_EQ(3, doc->get_Range()->get_Fields()->get_Count());
ASSERT_EQ(u" FORMDROPDOWN \u0001", doc->get_Range()->get_Fields()->idx_get(0)->GetFieldCode());
ASSERT_EQ(u" FORMCHECKBOX \u0001", doc->get_Range()->get_Fields()->idx_get(1)->GetFieldCode());
ASSERT_EQ(u" FORMTEXT \u0001", doc->get_Range()->get_Fields()->idx_get(2)->GetFieldCode());
// Allow each form field to accept a document visitor.
auto formFieldVisitor = MakeObject<ExFormFields::FormFieldVisitor>();
{
SharedPtr<System::Collections::Generic::IEnumerator<SharedPtr<FormField>>> fieldEnumerator = formFields->GetEnumerator();
while (fieldEnumerator->MoveNext())
{
fieldEnumerator->get_Current()->Accept(formFieldVisitor);
}
}
std::cout << formFieldVisitor->GetText() << std::endl;
doc->UpdateFields();
doc->Save(ArtifactsDir + u"FormFields.Visitor.html");
}
class FormFieldVisitor : public DocumentVisitor
{
public:
FormFieldVisitor()
{
mBuilder = MakeObject<System::Text::StringBuilder>();
}
VisitorAction VisitFormField(SharedPtr<FormField> formField) override
{
AppendLine(System::ObjectExt::ToString(formField->get_Type()) + u": \"" + formField->get_Name() + u"\"");
AppendLine(String(u"\tStatus: ") + (formField->get_Enabled() ? String(u"Enabled") : String(u"Disabled")));
AppendLine(String(u"\tHelp Text: ") + formField->get_HelpText());
AppendLine(String(u"\tEntry macro name: ") + formField->get_EntryMacro());
AppendLine(String(u"\tExit macro name: ") + formField->get_ExitMacro());
switch (formField->get_Type())
{
AppendLine(String(u"\tDrop-down items count: ") + formField->get_DropDownItems()->get_Count() + u", default selected item index: " +
formField->get_DropDownSelectedIndex());
AppendLine(String(u"\tDrop-down items: ") + String::Join(u", ", formField->get_DropDownItems()->LINQ_ToArray()));
break;
AppendLine(String(u"\tCheckbox size: ") + formField->get_CheckBoxSize());
AppendLine(String(u"\t") + u"Checkbox is currently: " + (formField->get_Checked() ? String(u"checked, ") : String(u"unchecked, ")) +
u"by default: " + (formField->get_Default() ? String(u"checked") : String(u"unchecked")));
break;
AppendLine(String(u"\tInput format: ") + formField->get_TextInputFormat());
AppendLine(String(u"\tCurrent contents: ") + formField->get_Result());
break;
default:
break;
}
// Let the visitor continue visiting other nodes.
}
String GetText()
{
return mBuilder->ToString();
}
private:
SharedPtr<System::Text::StringBuilder> mBuilder;
void AppendLine(String text)
{
mBuilder->Append(text + u'\n');
}
};

Implements Aspose::Words::Node.

◆ get_CalculateOnExit()

bool Aspose::Words::Fields::FormField::get_CalculateOnExit ( )

True if references to the specified form field are automatically updated whenever the field is exited.

Setting CalculateOnExit only affects the behavior of the form field when the document is opened in Microsoft Word. Aspose.Words never updates references to the form field.

Examples

Shows how insert different kinds of form fields into a document, and process them with using a document visitor implementation.

void Visitor()
{
auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Use a document builder to insert a combo box.
builder->Write(u"Choose a value from this combo box: ");
SharedPtr<FormField> comboBox = builder->InsertComboBox(u"MyComboBox", MakeArray<String>({u"One", u"Two", u"Three"}), 0);
comboBox->set_CalculateOnExit(true);
ASSERT_EQ(3, comboBox->get_DropDownItems()->get_Count());
ASSERT_EQ(0, comboBox->get_DropDownSelectedIndex());
ASSERT_TRUE(comboBox->get_Enabled());
builder->InsertBreak(BreakType::ParagraphBreak);
// Use a document builder to insert a check box.
builder->Write(u"Click this check box to tick/untick it: ");
SharedPtr<FormField> checkBox = builder->InsertCheckBox(u"MyCheckBox", false, 50);
checkBox->set_IsCheckBoxExactSize(true);
checkBox->set_HelpText(u"Right click to check this box");
checkBox->set_OwnHelp(true);
checkBox->set_StatusText(u"Checkbox status text");
checkBox->set_OwnStatus(true);
ASPOSE_ASSERT_EQ(50.0, checkBox->get_CheckBoxSize());
ASSERT_FALSE(checkBox->get_Checked());
ASSERT_FALSE(checkBox->get_Default());
builder->InsertBreak(BreakType::ParagraphBreak);
// Use a document builder to insert text input form field.
builder->Write(u"Enter text here: ");
SharedPtr<FormField> textInput = builder->InsertTextInput(u"MyTextInput", TextFormFieldType::Regular, u"", u"Placeholder text", 50);
textInput->set_EntryMacro(u"EntryMacro");
textInput->set_ExitMacro(u"ExitMacro");
textInput->set_TextInputDefault(u"Regular");
textInput->set_TextInputFormat(u"FIRST CAPITAL");
textInput->SetTextInputValue(System::ObjectExt::Box<String>(u"New placeholder text"));
ASSERT_EQ(TextFormFieldType::Regular, textInput->get_TextInputType());
ASSERT_EQ(50, textInput->get_MaxLength());
// This collection contains all our form fields.
SharedPtr<FormFieldCollection> formFields = doc->get_Range()->get_FormFields();
ASSERT_EQ(3, formFields->get_Count());
// Fields display our form fields. We can see their field codes by opening this document
// in Microsoft and pressing Alt + F9. These fields have no switches,
// and members of the FormField object fully govern their form fields' content.
ASSERT_EQ(3, doc->get_Range()->get_Fields()->get_Count());
ASSERT_EQ(u" FORMDROPDOWN \u0001", doc->get_Range()->get_Fields()->idx_get(0)->GetFieldCode());
ASSERT_EQ(u" FORMCHECKBOX \u0001", doc->get_Range()->get_Fields()->idx_get(1)->GetFieldCode());
ASSERT_EQ(u" FORMTEXT \u0001", doc->get_Range()->get_Fields()->idx_get(2)->GetFieldCode());
// Allow each form field to accept a document visitor.
auto formFieldVisitor = MakeObject<ExFormFields::FormFieldVisitor>();
{
SharedPtr<System::Collections::Generic::IEnumerator<SharedPtr<FormField>>> fieldEnumerator = formFields->GetEnumerator();
while (fieldEnumerator->MoveNext())
{
fieldEnumerator->get_Current()->Accept(formFieldVisitor);
}
}
std::cout << formFieldVisitor->GetText() << std::endl;
doc->UpdateFields();
doc->Save(ArtifactsDir + u"FormFields.Visitor.html");
}
class FormFieldVisitor : public DocumentVisitor
{
public:
FormFieldVisitor()
{
mBuilder = MakeObject<System::Text::StringBuilder>();
}
VisitorAction VisitFormField(SharedPtr<FormField> formField) override
{
AppendLine(System::ObjectExt::ToString(formField->get_Type()) + u": \"" + formField->get_Name() + u"\"");
AppendLine(String(u"\tStatus: ") + (formField->get_Enabled() ? String(u"Enabled") : String(u"Disabled")));
AppendLine(String(u"\tHelp Text: ") + formField->get_HelpText());
AppendLine(String(u"\tEntry macro name: ") + formField->get_EntryMacro());
AppendLine(String(u"\tExit macro name: ") + formField->get_ExitMacro());
switch (formField->get_Type())
{
AppendLine(String(u"\tDrop-down items count: ") + formField->get_DropDownItems()->get_Count() + u", default selected item index: " +
formField->get_DropDownSelectedIndex());
AppendLine(String(u"\tDrop-down items: ") + String::Join(u", ", formField->get_DropDownItems()->LINQ_ToArray()));
break;
AppendLine(String(u"\tCheckbox size: ") + formField->get_CheckBoxSize());
AppendLine(String(u"\t") + u"Checkbox is currently: " + (formField->get_Checked() ? String(u"checked, ") : String(u"unchecked, ")) +
u"by default: " + (formField->get_Default() ? String(u"checked") : String(u"unchecked")));
break;
AppendLine(String(u"\tInput format: ") + formField->get_TextInputFormat());
AppendLine(String(u"\tCurrent contents: ") + formField->get_Result());
break;
default:
break;
}
// Let the visitor continue visiting other nodes.
}
String GetText()
{
return mBuilder->ToString();
}
private:
SharedPtr<System::Text::StringBuilder> mBuilder;
void AppendLine(String text)
{
mBuilder->Append(text + u'\n');
}
};

◆ get_CheckBoxSize()

double Aspose::Words::Fields::FormField::get_CheckBoxSize ( )

Gets or sets the size of the checkbox in points. Has effect only when IsCheckBoxExactSize is true.

Applicable for a check box form field only.

See also
Aspose::Words::Fields::FormField::get_IsCheckBoxExactSize
Examples

Shows how insert different kinds of form fields into a document, and process them with using a document visitor implementation.

void Visitor()
{
auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Use a document builder to insert a combo box.
builder->Write(u"Choose a value from this combo box: ");
SharedPtr<FormField> comboBox = builder->InsertComboBox(u"MyComboBox", MakeArray<String>({u"One", u"Two", u"Three"}), 0);
comboBox->set_CalculateOnExit(true);
ASSERT_EQ(3, comboBox->get_DropDownItems()->get_Count());
ASSERT_EQ(0, comboBox->get_DropDownSelectedIndex());
ASSERT_TRUE(comboBox->get_Enabled());
builder->InsertBreak(BreakType::ParagraphBreak);
// Use a document builder to insert a check box.
builder->Write(u"Click this check box to tick/untick it: ");
SharedPtr<FormField> checkBox = builder->InsertCheckBox(u"MyCheckBox", false, 50);
checkBox->set_IsCheckBoxExactSize(true);
checkBox->set_HelpText(u"Right click to check this box");
checkBox->set_OwnHelp(true);
checkBox->set_StatusText(u"Checkbox status text");
checkBox->set_OwnStatus(true);
ASPOSE_ASSERT_EQ(50.0, checkBox->get_CheckBoxSize());
ASSERT_FALSE(checkBox->get_Checked());
ASSERT_FALSE(checkBox->get_Default());
builder->InsertBreak(BreakType::ParagraphBreak);
// Use a document builder to insert text input form field.
builder->Write(u"Enter text here: ");
SharedPtr<FormField> textInput = builder->InsertTextInput(u"MyTextInput", TextFormFieldType::Regular, u"", u"Placeholder text", 50);
textInput->set_EntryMacro(u"EntryMacro");
textInput->set_ExitMacro(u"ExitMacro");
textInput->set_TextInputDefault(u"Regular");
textInput->set_TextInputFormat(u"FIRST CAPITAL");
textInput->SetTextInputValue(System::ObjectExt::Box<String>(u"New placeholder text"));
ASSERT_EQ(TextFormFieldType::Regular, textInput->get_TextInputType());
ASSERT_EQ(50, textInput->get_MaxLength());
// This collection contains all our form fields.
SharedPtr<FormFieldCollection> formFields = doc->get_Range()->get_FormFields();
ASSERT_EQ(3, formFields->get_Count());
// Fields display our form fields. We can see their field codes by opening this document
// in Microsoft and pressing Alt + F9. These fields have no switches,
// and members of the FormField object fully govern their form fields' content.
ASSERT_EQ(3, doc->get_Range()->get_Fields()->get_Count());
ASSERT_EQ(u" FORMDROPDOWN \u0001", doc->get_Range()->get_Fields()->idx_get(0)->GetFieldCode());
ASSERT_EQ(u" FORMCHECKBOX \u0001", doc->get_Range()->get_Fields()->idx_get(1)->GetFieldCode());
ASSERT_EQ(u" FORMTEXT \u0001", doc->get_Range()->get_Fields()->idx_get(2)->GetFieldCode());
// Allow each form field to accept a document visitor.
auto formFieldVisitor = MakeObject<ExFormFields::FormFieldVisitor>();
{
SharedPtr<System::Collections::Generic::IEnumerator<SharedPtr<FormField>>> fieldEnumerator = formFields->GetEnumerator();
while (fieldEnumerator->MoveNext())
{
fieldEnumerator->get_Current()->Accept(formFieldVisitor);
}
}
std::cout << formFieldVisitor->GetText() << std::endl;
doc->UpdateFields();
doc->Save(ArtifactsDir + u"FormFields.Visitor.html");
}
class FormFieldVisitor : public DocumentVisitor
{
public:
FormFieldVisitor()
{
mBuilder = MakeObject<System::Text::StringBuilder>();
}
VisitorAction VisitFormField(SharedPtr<FormField> formField) override
{
AppendLine(System::ObjectExt::ToString(formField->get_Type()) + u": \"" + formField->get_Name() + u"\"");
AppendLine(String(u"\tStatus: ") + (formField->get_Enabled() ? String(u"Enabled") : String(u"Disabled")));
AppendLine(String(u"\tHelp Text: ") + formField->get_HelpText());
AppendLine(String(u"\tEntry macro name: ") + formField->get_EntryMacro());
AppendLine(String(u"\tExit macro name: ") + formField->get_ExitMacro());
switch (formField->get_Type())
{
AppendLine(String(u"\tDrop-down items count: ") + formField->get_DropDownItems()->get_Count() + u", default selected item index: " +
formField->get_DropDownSelectedIndex());
AppendLine(String(u"\tDrop-down items: ") + String::Join(u", ", formField->get_DropDownItems()->LINQ_ToArray()));
break;
AppendLine(String(u"\tCheckbox size: ") + formField->get_CheckBoxSize());
AppendLine(String(u"\t") + u"Checkbox is currently: " + (formField->get_Checked() ? String(u"checked, ") : String(u"unchecked, ")) +
u"by default: " + (formField->get_Default() ? String(u"checked") : String(u"unchecked")));
break;
AppendLine(String(u"\tInput format: ") + formField->get_TextInputFormat());
AppendLine(String(u"\tCurrent contents: ") + formField->get_Result());
break;
default:
break;
}
// Let the visitor continue visiting other nodes.
}
String GetText()
{
return mBuilder->ToString();
}
private:
SharedPtr<System::Text::StringBuilder> mBuilder;
void AppendLine(String text)
{
mBuilder->Append(text + u'\n');
}
};

◆ get_Checked()

bool Aspose::Words::Fields::FormField::get_Checked ( )

Gets or sets the checked status of the check box form field. Default value for this property is false.

Applicable for a check box form field only.

Examples

Shows how insert different kinds of form fields into a document, and process them with using a document visitor implementation.

void Visitor()
{
auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Use a document builder to insert a combo box.
builder->Write(u"Choose a value from this combo box: ");
SharedPtr<FormField> comboBox = builder->InsertComboBox(u"MyComboBox", MakeArray<String>({u"One", u"Two", u"Three"}), 0);
comboBox->set_CalculateOnExit(true);
ASSERT_EQ(3, comboBox->get_DropDownItems()->get_Count());
ASSERT_EQ(0, comboBox->get_DropDownSelectedIndex());
ASSERT_TRUE(comboBox->get_Enabled());
builder->InsertBreak(BreakType::ParagraphBreak);
// Use a document builder to insert a check box.
builder->Write(u"Click this check box to tick/untick it: ");
SharedPtr<FormField> checkBox = builder->InsertCheckBox(u"MyCheckBox", false, 50);
checkBox->set_IsCheckBoxExactSize(true);
checkBox->set_HelpText(u"Right click to check this box");
checkBox->set_OwnHelp(true);
checkBox->set_StatusText(u"Checkbox status text");
checkBox->set_OwnStatus(true);
ASPOSE_ASSERT_EQ(50.0, checkBox->get_CheckBoxSize());
ASSERT_FALSE(checkBox->get_Checked());
ASSERT_FALSE(checkBox->get_Default());
builder->InsertBreak(BreakType::ParagraphBreak);
// Use a document builder to insert text input form field.
builder->Write(u"Enter text here: ");
SharedPtr<FormField> textInput = builder->InsertTextInput(u"MyTextInput", TextFormFieldType::Regular, u"", u"Placeholder text", 50);
textInput->set_EntryMacro(u"EntryMacro");
textInput->set_ExitMacro(u"ExitMacro");
textInput->set_TextInputDefault(u"Regular");
textInput->set_TextInputFormat(u"FIRST CAPITAL");
textInput->SetTextInputValue(System::ObjectExt::Box<String>(u"New placeholder text"));
ASSERT_EQ(TextFormFieldType::Regular, textInput->get_TextInputType());
ASSERT_EQ(50, textInput->get_MaxLength());
// This collection contains all our form fields.
SharedPtr<FormFieldCollection> formFields = doc->get_Range()->get_FormFields();
ASSERT_EQ(3, formFields->get_Count());
// Fields display our form fields. We can see their field codes by opening this document
// in Microsoft and pressing Alt + F9. These fields have no switches,
// and members of the FormField object fully govern their form fields' content.
ASSERT_EQ(3, doc->get_Range()->get_Fields()->get_Count());
ASSERT_EQ(u" FORMDROPDOWN \u0001", doc->get_Range()->get_Fields()->idx_get(0)->GetFieldCode());
ASSERT_EQ(u" FORMCHECKBOX \u0001", doc->get_Range()->get_Fields()->idx_get(1)->GetFieldCode());
ASSERT_EQ(u" FORMTEXT \u0001", doc->get_Range()->get_Fields()->idx_get(2)->GetFieldCode());
// Allow each form field to accept a document visitor.
auto formFieldVisitor = MakeObject<ExFormFields::FormFieldVisitor>();
{
SharedPtr<System::Collections::Generic::IEnumerator<SharedPtr<FormField>>> fieldEnumerator = formFields->GetEnumerator();
while (fieldEnumerator->MoveNext())
{
fieldEnumerator->get_Current()->Accept(formFieldVisitor);
}
}
std::cout << formFieldVisitor->GetText() << std::endl;
doc->UpdateFields();
doc->Save(ArtifactsDir + u"FormFields.Visitor.html");
}
class FormFieldVisitor : public DocumentVisitor
{
public:
FormFieldVisitor()
{
mBuilder = MakeObject<System::Text::StringBuilder>();
}
VisitorAction VisitFormField(SharedPtr<FormField> formField) override
{
AppendLine(System::ObjectExt::ToString(formField->get_Type()) + u": \"" + formField->get_Name() + u"\"");
AppendLine(String(u"\tStatus: ") + (formField->get_Enabled() ? String(u"Enabled") : String(u"Disabled")));
AppendLine(String(u"\tHelp Text: ") + formField->get_HelpText());
AppendLine(String(u"\tEntry macro name: ") + formField->get_EntryMacro());
AppendLine(String(u"\tExit macro name: ") + formField->get_ExitMacro());
switch (formField->get_Type())
{
AppendLine(String(u"\tDrop-down items count: ") + formField->get_DropDownItems()->get_Count() + u", default selected item index: " +
formField->get_DropDownSelectedIndex());
AppendLine(String(u"\tDrop-down items: ") + String::Join(u", ", formField->get_DropDownItems()->LINQ_ToArray()));
break;
AppendLine(String(u"\tCheckbox size: ") + formField->get_CheckBoxSize());
AppendLine(String(u"\t") + u"Checkbox is currently: " + (formField->get_Checked() ? String(u"checked, ") : String(u"unchecked, ")) +
u"by default: " + (formField->get_Default() ? String(u"checked") : String(u"unchecked")));
break;
AppendLine(String(u"\tInput format: ") + formField->get_TextInputFormat());
AppendLine(String(u"\tCurrent contents: ") + formField->get_Result());
break;
default:
break;
}
// Let the visitor continue visiting other nodes.
}
String GetText()
{
return mBuilder->ToString();
}
private:
SharedPtr<System::Text::StringBuilder> mBuilder;
void AppendLine(String text)
{
mBuilder->Append(text + u'\n');
}
};

◆ get_Default()

bool Aspose::Words::Fields::FormField::get_Default ( )

Gets or sets the default value of the check box form field. Default value for this property is false.

Applicable for a check box form field only.

Examples

Shows how insert different kinds of form fields into a document, and process them with using a document visitor implementation.

void Visitor()
{
auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Use a document builder to insert a combo box.
builder->Write(u"Choose a value from this combo box: ");
SharedPtr<FormField> comboBox = builder->InsertComboBox(u"MyComboBox", MakeArray<String>({u"One", u"Two", u"Three"}), 0);
comboBox->set_CalculateOnExit(true);
ASSERT_EQ(3, comboBox->get_DropDownItems()->get_Count());
ASSERT_EQ(0, comboBox->get_DropDownSelectedIndex());
ASSERT_TRUE(comboBox->get_Enabled());
builder->InsertBreak(BreakType::ParagraphBreak);
// Use a document builder to insert a check box.
builder->Write(u"Click this check box to tick/untick it: ");
SharedPtr<FormField> checkBox = builder->InsertCheckBox(u"MyCheckBox", false, 50);
checkBox->set_IsCheckBoxExactSize(true);
checkBox->set_HelpText(u"Right click to check this box");
checkBox->set_OwnHelp(true);
checkBox->set_StatusText(u"Checkbox status text");
checkBox->set_OwnStatus(true);
ASPOSE_ASSERT_EQ(50.0, checkBox->get_CheckBoxSize());
ASSERT_FALSE(checkBox->get_Checked());
ASSERT_FALSE(checkBox->get_Default());
builder->InsertBreak(BreakType::ParagraphBreak);
// Use a document builder to insert text input form field.
builder->Write(u"Enter text here: ");
SharedPtr<FormField> textInput = builder->InsertTextInput(u"MyTextInput", TextFormFieldType::Regular, u"", u"Placeholder text", 50);
textInput->set_EntryMacro(u"EntryMacro");
textInput->set_ExitMacro(u"ExitMacro");
textInput->set_TextInputDefault(u"Regular");
textInput->set_TextInputFormat(u"FIRST CAPITAL");
textInput->SetTextInputValue(System::ObjectExt::Box<String>(u"New placeholder text"));
ASSERT_EQ(TextFormFieldType::Regular, textInput->get_TextInputType());
ASSERT_EQ(50, textInput->get_MaxLength());
// This collection contains all our form fields.
SharedPtr<FormFieldCollection> formFields = doc->get_Range()->get_FormFields();
ASSERT_EQ(3, formFields->get_Count());
// Fields display our form fields. We can see their field codes by opening this document
// in Microsoft and pressing Alt + F9. These fields have no switches,
// and members of the FormField object fully govern their form fields' content.
ASSERT_EQ(3, doc->get_Range()->get_Fields()->get_Count());
ASSERT_EQ(u" FORMDROPDOWN \u0001", doc->get_Range()->get_Fields()->idx_get(0)->GetFieldCode());
ASSERT_EQ(u" FORMCHECKBOX \u0001", doc->get_Range()->get_Fields()->idx_get(1)->GetFieldCode());
ASSERT_EQ(u" FORMTEXT \u0001", doc->get_Range()->get_Fields()->idx_get(2)->GetFieldCode());
// Allow each form field to accept a document visitor.
auto formFieldVisitor = MakeObject<ExFormFields::FormFieldVisitor>();
{
SharedPtr<System::Collections::Generic::IEnumerator<SharedPtr<FormField>>> fieldEnumerator = formFields->GetEnumerator();
while (fieldEnumerator->MoveNext())
{
fieldEnumerator->get_Current()->Accept(formFieldVisitor);
}
}
std::cout << formFieldVisitor->GetText() << std::endl;
doc->UpdateFields();
doc->Save(ArtifactsDir + u"FormFields.Visitor.html");
}
class FormFieldVisitor : public DocumentVisitor
{
public:
FormFieldVisitor()
{
mBuilder = MakeObject<System::Text::StringBuilder>();
}
VisitorAction VisitFormField(SharedPtr<FormField> formField) override
{
AppendLine(System::ObjectExt::ToString(formField->get_Type()) + u": \"" + formField->get_Name() + u"\"");
AppendLine(String(u"\tStatus: ") + (formField->get_Enabled() ? String(u"Enabled") : String(u"Disabled")));
AppendLine(String(u"\tHelp Text: ") + formField->get_HelpText());
AppendLine(String(u"\tEntry macro name: ") + formField->get_EntryMacro());
AppendLine(String(u"\tExit macro name: ") + formField->get_ExitMacro());
switch (formField->get_Type())
{
AppendLine(String(u"\tDrop-down items count: ") + formField->get_DropDownItems()->get_Count() + u", default selected item index: " +
formField->get_DropDownSelectedIndex());
AppendLine(String(u"\tDrop-down items: ") + String::Join(u", ", formField->get_DropDownItems()->LINQ_ToArray()));
break;
AppendLine(String(u"\tCheckbox size: ") + formField->get_CheckBoxSize());
AppendLine(String(u"\t") + u"Checkbox is currently: " + (formField->get_Checked() ? String(u"checked, ") : String(u"unchecked, ")) +
u"by default: " + (formField->get_Default() ? String(u"checked") : String(u"unchecked")));
break;
AppendLine(String(u"\tInput format: ") + formField->get_TextInputFormat());
AppendLine(String(u"\tCurrent contents: ") + formField->get_Result());
break;
default:
break;
}
// Let the visitor continue visiting other nodes.
}
String GetText()
{
return mBuilder->ToString();
}
private:
SharedPtr<System::Text::StringBuilder> mBuilder;
void AppendLine(String text)
{
mBuilder->Append(text + u'\n');
}
};

◆ get_DropDownItems()

System::SharedPtr<Aspose::Words::Fields::DropDownItemCollection> Aspose::Words::Fields::FormField::get_DropDownItems ( )

Provides access to the items of a dropdown form field.

Microsoft Word allows maximum 25 items in a dropdown form field.

Examples

Shows how insert different kinds of form fields into a document, and process them with using a document visitor implementation.

void Visitor()
{
auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Use a document builder to insert a combo box.
builder->Write(u"Choose a value from this combo box: ");
SharedPtr<FormField> comboBox = builder->InsertComboBox(u"MyComboBox", MakeArray<String>({u"One", u"Two", u"Three"}), 0);
comboBox->set_CalculateOnExit(true);
ASSERT_EQ(3, comboBox->get_DropDownItems()->get_Count());
ASSERT_EQ(0, comboBox->get_DropDownSelectedIndex());
ASSERT_TRUE(comboBox->get_Enabled());
builder->InsertBreak(BreakType::ParagraphBreak);
// Use a document builder to insert a check box.
builder->Write(u"Click this check box to tick/untick it: ");
SharedPtr<FormField> checkBox = builder->InsertCheckBox(u"MyCheckBox", false, 50);
checkBox->set_IsCheckBoxExactSize(true);
checkBox->set_HelpText(u"Right click to check this box");
checkBox->set_OwnHelp(true);
checkBox->set_StatusText(u"Checkbox status text");
checkBox->set_OwnStatus(true);
ASPOSE_ASSERT_EQ(50.0, checkBox->get_CheckBoxSize());
ASSERT_FALSE(checkBox->get_Checked());
ASSERT_FALSE(checkBox->get_Default());
builder->InsertBreak(BreakType::ParagraphBreak);
// Use a document builder to insert text input form field.
builder->Write(u"Enter text here: ");
SharedPtr<FormField> textInput = builder->InsertTextInput(u"MyTextInput", TextFormFieldType::Regular, u"", u"Placeholder text", 50);
textInput->set_EntryMacro(u"EntryMacro");
textInput->set_ExitMacro(u"ExitMacro");
textInput->set_TextInputDefault(u"Regular");
textInput->set_TextInputFormat(u"FIRST CAPITAL");
textInput->SetTextInputValue(System::ObjectExt::Box<String>(u"New placeholder text"));
ASSERT_EQ(TextFormFieldType::Regular, textInput->get_TextInputType());
ASSERT_EQ(50, textInput->get_MaxLength());
// This collection contains all our form fields.
SharedPtr<FormFieldCollection> formFields = doc->get_Range()->get_FormFields();
ASSERT_EQ(3, formFields->get_Count());
// Fields display our form fields. We can see their field codes by opening this document
// in Microsoft and pressing Alt + F9. These fields have no switches,
// and members of the FormField object fully govern their form fields' content.
ASSERT_EQ(3, doc->get_Range()->get_Fields()->get_Count());
ASSERT_EQ(u" FORMDROPDOWN \u0001", doc->get_Range()->get_Fields()->idx_get(0)->GetFieldCode());
ASSERT_EQ(u" FORMCHECKBOX \u0001", doc->get_Range()->get_Fields()->idx_get(1)->GetFieldCode());
ASSERT_EQ(u" FORMTEXT \u0001", doc->get_Range()->get_Fields()->idx_get(2)->GetFieldCode());
// Allow each form field to accept a document visitor.
auto formFieldVisitor = MakeObject<ExFormFields::FormFieldVisitor>();
{
SharedPtr<System::Collections::Generic::IEnumerator<SharedPtr<FormField>>> fieldEnumerator = formFields->GetEnumerator();
while (fieldEnumerator->MoveNext())
{
fieldEnumerator->get_Current()->Accept(formFieldVisitor);
}
}
std::cout << formFieldVisitor->GetText() << std::endl;
doc->UpdateFields();
doc->Save(ArtifactsDir + u"FormFields.Visitor.html");
}
class FormFieldVisitor : public DocumentVisitor
{
public:
FormFieldVisitor()
{
mBuilder = MakeObject<System::Text::StringBuilder>();
}
VisitorAction VisitFormField(SharedPtr<FormField> formField) override
{
AppendLine(System::ObjectExt::ToString(formField->get_Type()) + u": \"" + formField->get_Name() + u"\"");
AppendLine(String(u"\tStatus: ") + (formField->get_Enabled() ? String(u"Enabled") : String(u"Disabled")));
AppendLine(String(u"\tHelp Text: ") + formField->get_HelpText());
AppendLine(String(u"\tEntry macro name: ") + formField->get_EntryMacro());
AppendLine(String(u"\tExit macro name: ") + formField->get_ExitMacro());
switch (formField->get_Type())
{
AppendLine(String(u"\tDrop-down items count: ") + formField->get_DropDownItems()->get_Count() + u", default selected item index: " +
formField->get_DropDownSelectedIndex());
AppendLine(String(u"\tDrop-down items: ") + String::Join(u", ", formField->get_DropDownItems()->LINQ_ToArray()));
break;
AppendLine(String(u"\tCheckbox size: ") + formField->get_CheckBoxSize());
AppendLine(String(u"\t") + u"Checkbox is currently: " + (formField->get_Checked() ? String(u"checked, ") : String(u"unchecked, ")) +
u"by default: " + (formField->get_Default() ? String(u"checked") : String(u"unchecked")));
break;
AppendLine(String(u"\tInput format: ") + formField->get_TextInputFormat());
AppendLine(String(u"\tCurrent contents: ") + formField->get_Result());
break;
default:
break;
}
// Let the visitor continue visiting other nodes.
}
String GetText()
{
return mBuilder->ToString();
}
private:
SharedPtr<System::Text::StringBuilder> mBuilder;
void AppendLine(String text)
{
mBuilder->Append(text + u'\n');
}
};

◆ get_DropDownSelectedIndex()

int32_t Aspose::Words::Fields::FormField::get_DropDownSelectedIndex ( )

Gets or sets the index specifying the currently selected item in a dropdown form field.

Examples

Shows how insert different kinds of form fields into a document, and process them with using a document visitor implementation.

void Visitor()
{
auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Use a document builder to insert a combo box.
builder->Write(u"Choose a value from this combo box: ");
SharedPtr<FormField> comboBox = builder->InsertComboBox(u"MyComboBox", MakeArray<String>({u"One", u"Two", u"Three"}), 0);
comboBox->set_CalculateOnExit(true);
ASSERT_EQ(3, comboBox->get_DropDownItems()->get_Count());
ASSERT_EQ(0, comboBox->get_DropDownSelectedIndex());
ASSERT_TRUE(comboBox->get_Enabled());
builder->InsertBreak(BreakType::ParagraphBreak);
// Use a document builder to insert a check box.
builder->Write(u"Click this check box to tick/untick it: ");
SharedPtr<FormField> checkBox = builder->InsertCheckBox(u"MyCheckBox", false, 50);
checkBox->set_IsCheckBoxExactSize(true);
checkBox->set_HelpText(u"Right click to check this box");
checkBox->set_OwnHelp(true);
checkBox->set_StatusText(u"Checkbox status text");
checkBox->set_OwnStatus(true);
ASPOSE_ASSERT_EQ(50.0, checkBox->get_CheckBoxSize());
ASSERT_FALSE(checkBox->get_Checked());
ASSERT_FALSE(checkBox->get_Default());
builder->InsertBreak(BreakType::ParagraphBreak);
// Use a document builder to insert text input form field.
builder->Write(u"Enter text here: ");
SharedPtr<FormField> textInput = builder->InsertTextInput(u"MyTextInput", TextFormFieldType::Regular, u"", u"Placeholder text", 50);
textInput->set_EntryMacro(u"EntryMacro");
textInput->set_ExitMacro(u"ExitMacro");
textInput->set_TextInputDefault(u"Regular");
textInput->set_TextInputFormat(u"FIRST CAPITAL");
textInput->SetTextInputValue(System::ObjectExt::Box<String>(u"New placeholder text"));
ASSERT_EQ(TextFormFieldType::Regular, textInput->get_TextInputType());
ASSERT_EQ(50, textInput->get_MaxLength());
// This collection contains all our form fields.
SharedPtr<FormFieldCollection> formFields = doc->get_Range()->get_FormFields();
ASSERT_EQ(3, formFields->get_Count());
// Fields display our form fields. We can see their field codes by opening this document
// in Microsoft and pressing Alt + F9. These fields have no switches,
// and members of the FormField object fully govern their form fields' content.
ASSERT_EQ(3, doc->get_Range()->get_Fields()->get_Count());
ASSERT_EQ(u" FORMDROPDOWN \u0001", doc->get_Range()->get_Fields()->idx_get(0)->GetFieldCode());
ASSERT_EQ(u" FORMCHECKBOX \u0001", doc->get_Range()->get_Fields()->idx_get(1)->GetFieldCode());
ASSERT_EQ(u" FORMTEXT \u0001", doc->get_Range()->get_Fields()->idx_get(2)->GetFieldCode());
// Allow each form field to accept a document visitor.
auto formFieldVisitor = MakeObject<ExFormFields::FormFieldVisitor>();
{
SharedPtr<System::Collections::Generic::IEnumerator<SharedPtr<FormField>>> fieldEnumerator = formFields->GetEnumerator();
while (fieldEnumerator->MoveNext())
{
fieldEnumerator->get_Current()->Accept(formFieldVisitor);
}
}
std::cout << formFieldVisitor->GetText() << std::endl;
doc->UpdateFields();
doc->Save(ArtifactsDir + u"FormFields.Visitor.html");
}
class FormFieldVisitor : public DocumentVisitor
{
public:
FormFieldVisitor()
{
mBuilder = MakeObject<System::Text::StringBuilder>();
}
VisitorAction VisitFormField(SharedPtr<FormField> formField) override
{
AppendLine(System::ObjectExt::ToString(formField->get_Type()) + u": \"" + formField->get_Name() + u"\"");
AppendLine(String(u"\tStatus: ") + (formField->get_Enabled() ? String(u"Enabled") : String(u"Disabled")));
AppendLine(String(u"\tHelp Text: ") + formField->get_HelpText());
AppendLine(String(u"\tEntry macro name: ") + formField->get_EntryMacro());
AppendLine(String(u"\tExit macro name: ") + formField->get_ExitMacro());
switch (formField->get_Type())
{
AppendLine(String(u"\tDrop-down items count: ") + formField->get_DropDownItems()->get_Count() + u", default selected item index: " +
formField->get_DropDownSelectedIndex());
AppendLine(String(u"\tDrop-down items: ") + String::Join(u", ", formField->get_DropDownItems()->LINQ_ToArray()));
break;
AppendLine(String(u"\tCheckbox size: ") + formField->get_CheckBoxSize());
AppendLine(String(u"\t") + u"Checkbox is currently: " + (formField->get_Checked() ? String(u"checked, ") : String(u"unchecked, ")) +
u"by default: " + (formField->get_Default() ? String(u"checked") : String(u"unchecked")));
break;
AppendLine(String(u"\tInput format: ") + formField->get_TextInputFormat());
AppendLine(String(u"\tCurrent contents: ") + formField->get_Result());
break;
default:
break;
}
// Let the visitor continue visiting other nodes.
}
String GetText()
{
return mBuilder->ToString();
}
private:
SharedPtr<System::Text::StringBuilder> mBuilder;
void AppendLine(String text)
{
mBuilder->Append(text + u'\n');
}
};

◆ get_Enabled()

bool Aspose::Words::Fields::FormField::get_Enabled ( )

True if a form field is enabled.

If a form field is enabled, its contents can be changed as the form is filled in.

Examples

Shows how insert different kinds of form fields into a document, and process them with using a document visitor implementation.

void Visitor()
{
auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Use a document builder to insert a combo box.
builder->Write(u"Choose a value from this combo box: ");
SharedPtr<FormField> comboBox = builder->InsertComboBox(u"MyComboBox", MakeArray<String>({u"One", u"Two", u"Three"}), 0);
comboBox->set_CalculateOnExit(true);
ASSERT_EQ(3, comboBox->get_DropDownItems()->get_Count());
ASSERT_EQ(0, comboBox->get_DropDownSelectedIndex());
ASSERT_TRUE(comboBox->get_Enabled());
builder->InsertBreak(BreakType::ParagraphBreak);
// Use a document builder to insert a check box.
builder->Write(u"Click this check box to tick/untick it: ");
SharedPtr<FormField> checkBox = builder->InsertCheckBox(u"MyCheckBox", false, 50);
checkBox->set_IsCheckBoxExactSize(true);
checkBox->set_HelpText(u"Right click to check this box");
checkBox->set_OwnHelp(true);
checkBox->set_StatusText(u"Checkbox status text");
checkBox->set_OwnStatus(true);
ASPOSE_ASSERT_EQ(50.0, checkBox->get_CheckBoxSize());
ASSERT_FALSE(checkBox->get_Checked());
ASSERT_FALSE(checkBox->get_Default());
builder->InsertBreak(BreakType::ParagraphBreak);
// Use a document builder to insert text input form field.
builder->Write(u"Enter text here: ");
SharedPtr<FormField> textInput = builder->InsertTextInput(u"MyTextInput", TextFormFieldType::Regular, u"", u"Placeholder text", 50);
textInput->set_EntryMacro(u"EntryMacro");
textInput->set_ExitMacro(u"ExitMacro");
textInput->set_TextInputDefault(u"Regular");
textInput->set_TextInputFormat(u"FIRST CAPITAL");
textInput->SetTextInputValue(System::ObjectExt::Box<String>(u"New placeholder text"));
ASSERT_EQ(TextFormFieldType::Regular, textInput->get_TextInputType());
ASSERT_EQ(50, textInput->get_MaxLength());
// This collection contains all our form fields.
SharedPtr<FormFieldCollection> formFields = doc->get_Range()->get_FormFields();
ASSERT_EQ(3, formFields->get_Count());
// Fields display our form fields. We can see their field codes by opening this document
// in Microsoft and pressing Alt + F9. These fields have no switches,
// and members of the FormField object fully govern their form fields' content.
ASSERT_EQ(3, doc->get_Range()->get_Fields()->get_Count());
ASSERT_EQ(u" FORMDROPDOWN \u0001", doc->get_Range()->get_Fields()->idx_get(0)->GetFieldCode());
ASSERT_EQ(u" FORMCHECKBOX \u0001", doc->get_Range()->get_Fields()->idx_get(1)->GetFieldCode());
ASSERT_EQ(u" FORMTEXT \u0001", doc->get_Range()->get_Fields()->idx_get(2)->GetFieldCode());
// Allow each form field to accept a document visitor.
auto formFieldVisitor = MakeObject<ExFormFields::FormFieldVisitor>();
{
SharedPtr<System::Collections::Generic::IEnumerator<SharedPtr<FormField>>> fieldEnumerator = formFields->GetEnumerator();
while (fieldEnumerator->MoveNext())
{
fieldEnumerator->get_Current()->Accept(formFieldVisitor);
}
}
std::cout << formFieldVisitor->GetText() << std::endl;
doc->UpdateFields();
doc->Save(ArtifactsDir + u"FormFields.Visitor.html");
}
class FormFieldVisitor : public DocumentVisitor
{
public:
FormFieldVisitor()
{
mBuilder = MakeObject<System::Text::StringBuilder>();
}
VisitorAction VisitFormField(SharedPtr<FormField> formField) override
{
AppendLine(System::ObjectExt::ToString(formField->get_Type()) + u": \"" + formField->get_Name() + u"\"");
AppendLine(String(u"\tStatus: ") + (formField->get_Enabled() ? String(u"Enabled") : String(u"Disabled")));
AppendLine(String(u"\tHelp Text: ") + formField->get_HelpText());
AppendLine(String(u"\tEntry macro name: ") + formField->get_EntryMacro());
AppendLine(String(u"\tExit macro name: ") + formField->get_ExitMacro());
switch (formField->get_Type())
{
AppendLine(String(u"\tDrop-down items count: ") + formField->get_DropDownItems()->get_Count() + u", default selected item index: " +
formField->get_DropDownSelectedIndex());
AppendLine(String(u"\tDrop-down items: ") + String::Join(u", ", formField->get_DropDownItems()->LINQ_ToArray()));
break;
AppendLine(String(u"\tCheckbox size: ") + formField->get_CheckBoxSize());
AppendLine(String(u"\t") + u"Checkbox is currently: " + (formField->get_Checked() ? String(u"checked, ") : String(u"unchecked, ")) +
u"by default: " + (formField->get_Default() ? String(u"checked") : String(u"unchecked")));
break;
AppendLine(String(u"\tInput format: ") + formField->get_TextInputFormat());
AppendLine(String(u"\tCurrent contents: ") + formField->get_Result());
break;
default:
break;
}
// Let the visitor continue visiting other nodes.
}
String GetText()
{
return mBuilder->ToString();
}
private:
SharedPtr<System::Text::StringBuilder> mBuilder;
void AppendLine(String text)
{
mBuilder->Append(text + u'\n');
}
};

◆ get_EntryMacro()

System::String Aspose::Words::Fields::FormField::get_EntryMacro ( )

Returns or sets an entry macro name for the form field.

The entry macro runs when the form field gets the focus in Microsoft Word.

Microsoft Word allows strings with at most 32 characters.

Examples

Shows how insert different kinds of form fields into a document, and process them with using a document visitor implementation.

void Visitor()
{
auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Use a document builder to insert a combo box.
builder->Write(u"Choose a value from this combo box: ");
SharedPtr<FormField> comboBox = builder->InsertComboBox(u"MyComboBox", MakeArray<String>({u"One", u"Two", u"Three"}), 0);
comboBox->set_CalculateOnExit(true);
ASSERT_EQ(3, comboBox->get_DropDownItems()->get_Count());
ASSERT_EQ(0, comboBox->get_DropDownSelectedIndex());
ASSERT_TRUE(comboBox->get_Enabled());
builder->InsertBreak(BreakType::ParagraphBreak);
// Use a document builder to insert a check box.
builder->Write(u"Click this check box to tick/untick it: ");
SharedPtr<FormField> checkBox = builder->InsertCheckBox(u"MyCheckBox", false, 50);
checkBox->set_IsCheckBoxExactSize(true);
checkBox->set_HelpText(u"Right click to check this box");
checkBox->set_OwnHelp(true);
checkBox->set_StatusText(u"Checkbox status text");
checkBox->set_OwnStatus(true);
ASPOSE_ASSERT_EQ(50.0, checkBox->get_CheckBoxSize());
ASSERT_FALSE(checkBox->get_Checked());
ASSERT_FALSE(checkBox->get_Default());
builder->InsertBreak(BreakType::ParagraphBreak);
// Use a document builder to insert text input form field.
builder->Write(u"Enter text here: ");
SharedPtr<FormField> textInput = builder->InsertTextInput(u"MyTextInput", TextFormFieldType::Regular, u"", u"Placeholder text", 50);
textInput->set_EntryMacro(u"EntryMacro");
textInput->set_ExitMacro(u"ExitMacro");
textInput->set_TextInputDefault(u"Regular");
textInput->set_TextInputFormat(u"FIRST CAPITAL");
textInput->SetTextInputValue(System::ObjectExt::Box<String>(u"New placeholder text"));
ASSERT_EQ(TextFormFieldType::Regular, textInput->get_TextInputType());
ASSERT_EQ(50, textInput->get_MaxLength());
// This collection contains all our form fields.
SharedPtr<FormFieldCollection> formFields = doc->get_Range()->get_FormFields();
ASSERT_EQ(3, formFields->get_Count());
// Fields display our form fields. We can see their field codes by opening this document
// in Microsoft and pressing Alt + F9. These fields have no switches,
// and members of the FormField object fully govern their form fields' content.
ASSERT_EQ(3, doc->get_Range()->get_Fields()->get_Count());
ASSERT_EQ(u" FORMDROPDOWN \u0001", doc->get_Range()->get_Fields()->idx_get(0)->GetFieldCode());
ASSERT_EQ(u" FORMCHECKBOX \u0001", doc->get_Range()->get_Fields()->idx_get(1)->GetFieldCode());
ASSERT_EQ(u" FORMTEXT \u0001", doc->get_Range()->get_Fields()->idx_get(2)->GetFieldCode());
// Allow each form field to accept a document visitor.
auto formFieldVisitor = MakeObject<ExFormFields::FormFieldVisitor>();
{
SharedPtr<System::Collections::Generic::IEnumerator<SharedPtr<FormField>>> fieldEnumerator = formFields->GetEnumerator();
while (fieldEnumerator->MoveNext())
{
fieldEnumerator->get_Current()->Accept(formFieldVisitor);
}
}
std::cout << formFieldVisitor->GetText() << std::endl;
doc->UpdateFields();
doc->Save(ArtifactsDir + u"FormFields.Visitor.html");
}
class FormFieldVisitor : public DocumentVisitor
{
public:
FormFieldVisitor()
{
mBuilder = MakeObject<System::Text::StringBuilder>();
}
VisitorAction VisitFormField(SharedPtr<FormField> formField) override
{
AppendLine(System::ObjectExt::ToString(formField->get_Type()) + u": \"" + formField->get_Name() + u"\"");
AppendLine(String(u"\tStatus: ") + (formField->get_Enabled() ? String(u"Enabled") : String(u"Disabled")));
AppendLine(String(u"\tHelp Text: ") + formField->get_HelpText());
AppendLine(String(u"\tEntry macro name: ") + formField->get_EntryMacro());
AppendLine(String(u"\tExit macro name: ") + formField->get_ExitMacro());
switch (formField->get_Type())
{
AppendLine(String(u"\tDrop-down items count: ") + formField->get_DropDownItems()->get_Count() + u", default selected item index: " +
formField->get_DropDownSelectedIndex());
AppendLine(String(u"\tDrop-down items: ") + String::Join(u", ", formField->get_DropDownItems()->LINQ_ToArray()));
break;
AppendLine(String(u"\tCheckbox size: ") + formField->get_CheckBoxSize());
AppendLine(String(u"\t") + u"Checkbox is currently: " + (formField->get_Checked() ? String(u"checked, ") : String(u"unchecked, ")) +
u"by default: " + (formField->get_Default() ? String(u"checked") : String(u"unchecked")));
break;
AppendLine(String(u"\tInput format: ") + formField->get_TextInputFormat());
AppendLine(String(u"\tCurrent contents: ") + formField->get_Result());
break;
default:
break;
}
// Let the visitor continue visiting other nodes.
}
String GetText()
{
return mBuilder->ToString();
}
private:
SharedPtr<System::Text::StringBuilder> mBuilder;
void AppendLine(String text)
{
mBuilder->Append(text + u'\n');
}
};

◆ get_ExitMacro()

System::String Aspose::Words::Fields::FormField::get_ExitMacro ( )

Returns or sets an exit macro name for the form field.

The exit macro runs when the form field loses the focus in Microsoft Word.

Microsoft Word allows strings with at most 32 characters.

Examples

Shows how insert different kinds of form fields into a document, and process them with using a document visitor implementation.

void Visitor()
{
auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Use a document builder to insert a combo box.
builder->Write(u"Choose a value from this combo box: ");
SharedPtr<FormField> comboBox = builder->InsertComboBox(u"MyComboBox", MakeArray<String>({u"One", u"Two", u"Three"}), 0);
comboBox->set_CalculateOnExit(true);
ASSERT_EQ(3, comboBox->get_DropDownItems()->get_Count());
ASSERT_EQ(0, comboBox->get_DropDownSelectedIndex());
ASSERT_TRUE(comboBox->get_Enabled());
builder->InsertBreak(BreakType::ParagraphBreak);
// Use a document builder to insert a check box.
builder->Write(u"Click this check box to tick/untick it: ");
SharedPtr<FormField> checkBox = builder->InsertCheckBox(u"MyCheckBox", false, 50);
checkBox->set_IsCheckBoxExactSize(true);
checkBox->set_HelpText(u"Right click to check this box");
checkBox->set_OwnHelp(true);
checkBox->set_StatusText(u"Checkbox status text");
checkBox->set_OwnStatus(true);
ASPOSE_ASSERT_EQ(50.0, checkBox->get_CheckBoxSize());
ASSERT_FALSE(checkBox->get_Checked());
ASSERT_FALSE(checkBox->get_Default());
builder->InsertBreak(BreakType::ParagraphBreak);
// Use a document builder to insert text input form field.
builder->Write(u"Enter text here: ");
SharedPtr<FormField> textInput = builder->InsertTextInput(u"MyTextInput", TextFormFieldType::Regular, u"", u"Placeholder text", 50);
textInput->set_EntryMacro(u"EntryMacro");
textInput->set_ExitMacro(u"ExitMacro");
textInput->set_TextInputDefault(u"Regular");
textInput->set_TextInputFormat(u"FIRST CAPITAL");
textInput->SetTextInputValue(System::ObjectExt::Box<String>(u"New placeholder text"));
ASSERT_EQ(TextFormFieldType::Regular, textInput->get_TextInputType());
ASSERT_EQ(50, textInput->get_MaxLength());
// This collection contains all our form fields.
SharedPtr<FormFieldCollection> formFields = doc->get_Range()->get_FormFields();
ASSERT_EQ(3, formFields->get_Count());
// Fields display our form fields. We can see their field codes by opening this document
// in Microsoft and pressing Alt + F9. These fields have no switches,
// and members of the FormField object fully govern their form fields' content.
ASSERT_EQ(3, doc->get_Range()->get_Fields()->get_Count());
ASSERT_EQ(u" FORMDROPDOWN \u0001", doc->get_Range()->get_Fields()->idx_get(0)->GetFieldCode());
ASSERT_EQ(u" FORMCHECKBOX \u0001", doc->get_Range()->get_Fields()->idx_get(1)->GetFieldCode());
ASSERT_EQ(u" FORMTEXT \u0001", doc->get_Range()->get_Fields()->idx_get(2)->GetFieldCode());
// Allow each form field to accept a document visitor.
auto formFieldVisitor = MakeObject<ExFormFields::FormFieldVisitor>();
{
SharedPtr<System::Collections::Generic::IEnumerator<SharedPtr<FormField>>> fieldEnumerator = formFields->GetEnumerator();
while (fieldEnumerator->MoveNext())
{
fieldEnumerator->get_Current()->Accept(formFieldVisitor);
}
}
std::cout << formFieldVisitor->GetText() << std::endl;
doc->UpdateFields();
doc->Save(ArtifactsDir + u"FormFields.Visitor.html");
}
class FormFieldVisitor : public DocumentVisitor
{
public:
FormFieldVisitor()
{
mBuilder = MakeObject<System::Text::StringBuilder>();
}
VisitorAction VisitFormField(SharedPtr<FormField> formField) override
{
AppendLine(System::ObjectExt::ToString(formField->get_Type()) + u": \"" + formField->get_Name() + u"\"");
AppendLine(String(u"\tStatus: ") + (formField->get_Enabled() ? String(u"Enabled") : String(u"Disabled")));
AppendLine(String(u"\tHelp Text: ") + formField->get_HelpText());
AppendLine(String(u"\tEntry macro name: ") + formField->get_EntryMacro());
AppendLine(String(u"\tExit macro name: ") + formField->get_ExitMacro());
switch (formField->get_Type())
{
AppendLine(String(u"\tDrop-down items count: ") + formField->get_DropDownItems()->get_Count() + u", default selected item index: " +
formField->get_DropDownSelectedIndex());
AppendLine(String(u"\tDrop-down items: ") + String::Join(u", ", formField->get_DropDownItems()->LINQ_ToArray()));
break;
AppendLine(String(u"\tCheckbox size: ") + formField->get_CheckBoxSize());
AppendLine(String(u"\t") + u"Checkbox is currently: " + (formField->get_Checked() ? String(u"checked, ") : String(u"unchecked, ")) +
u"by default: " + (formField->get_Default() ? String(u"checked") : String(u"unchecked")));
break;
AppendLine(String(u"\tInput format: ") + formField->get_TextInputFormat());
AppendLine(String(u"\tCurrent contents: ") + formField->get_Result());
break;
default:
break;
}
// Let the visitor continue visiting other nodes.
}
String GetText()
{
return mBuilder->ToString();
}
private:
SharedPtr<System::Text::StringBuilder> mBuilder;
void AppendLine(String text)
{
mBuilder->Append(text + u'\n');
}
};

◆ get_HelpText()

System::String Aspose::Words::Fields::FormField::get_HelpText ( )

Returns or sets the text that's displayed in a message box when the form field has the focus and the user presses F1.

If the OwnHelp property is set to True, HelpText specifies the text string value. If OwnHelp is set to False, HelpText specifies the name of an AutoText entry that contains help text for the form field.

Microsoft Word allows strings with at most 255 characters.

Examples

Shows how insert different kinds of form fields into a document, and process them with using a document visitor implementation.

void Visitor()
{
auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Use a document builder to insert a combo box.
builder->Write(u"Choose a value from this combo box: ");
SharedPtr<FormField> comboBox = builder->InsertComboBox(u"MyComboBox", MakeArray<String>({u"One", u"Two", u"Three"}), 0);
comboBox->set_CalculateOnExit(true);
ASSERT_EQ(3, comboBox->get_DropDownItems()->get_Count());
ASSERT_EQ(0, comboBox->get_DropDownSelectedIndex());
ASSERT_TRUE(comboBox->get_Enabled());
builder->InsertBreak(BreakType::ParagraphBreak);
// Use a document builder to insert a check box.
builder->Write(u"Click this check box to tick/untick it: ");
SharedPtr<FormField> checkBox = builder->InsertCheckBox(u"MyCheckBox", false, 50);
checkBox->set_IsCheckBoxExactSize(true);
checkBox->set_HelpText(u"Right click to check this box");
checkBox->set_OwnHelp(true);
checkBox->set_StatusText(u"Checkbox status text");
checkBox->set_OwnStatus(true);
ASPOSE_ASSERT_EQ(50.0, checkBox->get_CheckBoxSize());
ASSERT_FALSE(checkBox->get_Checked());
ASSERT_FALSE(checkBox->get_Default());
builder->InsertBreak(BreakType::ParagraphBreak);
// Use a document builder to insert text input form field.
builder->Write(u"Enter text here: ");
SharedPtr<FormField> textInput = builder->InsertTextInput(u"MyTextInput", TextFormFieldType::Regular, u"", u"Placeholder text", 50);
textInput->set_EntryMacro(u"EntryMacro");
textInput->set_ExitMacro(u"ExitMacro");
textInput->set_TextInputDefault(u"Regular");
textInput->set_TextInputFormat(u"FIRST CAPITAL");
textInput->SetTextInputValue(System::ObjectExt::Box<String>(u"New placeholder text"));
ASSERT_EQ(TextFormFieldType::Regular, textInput->get_TextInputType());
ASSERT_EQ(50, textInput->get_MaxLength());
// This collection contains all our form fields.
SharedPtr<FormFieldCollection> formFields = doc->get_Range()->get_FormFields();
ASSERT_EQ(3, formFields->get_Count());
// Fields display our form fields. We can see their field codes by opening this document
// in Microsoft and pressing Alt + F9. These fields have no switches,
// and members of the FormField object fully govern their form fields' content.
ASSERT_EQ(3, doc->get_Range()->get_Fields()->get_Count());
ASSERT_EQ(u" FORMDROPDOWN \u0001", doc->get_Range()->get_Fields()->idx_get(0)->GetFieldCode());
ASSERT_EQ(u" FORMCHECKBOX \u0001", doc->get_Range()->get_Fields()->idx_get(1)->GetFieldCode());
ASSERT_EQ(u" FORMTEXT \u0001", doc->get_Range()->get_Fields()->idx_get(2)->GetFieldCode());
// Allow each form field to accept a document visitor.
auto formFieldVisitor = MakeObject<ExFormFields::FormFieldVisitor>();
{
SharedPtr<System::Collections::Generic::IEnumerator<SharedPtr<FormField>>> fieldEnumerator = formFields->GetEnumerator();
while (fieldEnumerator->MoveNext())
{
fieldEnumerator->get_Current()->Accept(formFieldVisitor);
}
}
std::cout << formFieldVisitor->GetText() << std::endl;
doc->UpdateFields();
doc->Save(ArtifactsDir + u"FormFields.Visitor.html");
}
class FormFieldVisitor : public DocumentVisitor
{
public:
FormFieldVisitor()
{
mBuilder = MakeObject<System::Text::StringBuilder>();
}
VisitorAction VisitFormField(SharedPtr<FormField> formField) override
{
AppendLine(System::ObjectExt::ToString(formField->get_Type()) + u": \"" + formField->get_Name() + u"\"");
AppendLine(String(u"\tStatus: ") + (formField->get_Enabled() ? String(u"Enabled") : String(u"Disabled")));
AppendLine(String(u"\tHelp Text: ") + formField->get_HelpText());
AppendLine(String(u"\tEntry macro name: ") + formField->get_EntryMacro());
AppendLine(String(u"\tExit macro name: ") + formField->get_ExitMacro());
switch (formField->get_Type())
{
AppendLine(String(u"\tDrop-down items count: ") + formField->get_DropDownItems()->get_Count() + u", default selected item index: " +
formField->get_DropDownSelectedIndex());
AppendLine(String(u"\tDrop-down items: ") + String::Join(u", ", formField->get_DropDownItems()->LINQ_ToArray()));
break;
AppendLine(String(u"\tCheckbox size: ") + formField->get_CheckBoxSize());
AppendLine(String(u"\t") + u"Checkbox is currently: " + (formField->get_Checked() ? String(u"checked, ") : String(u"unchecked, ")) +
u"by default: " + (formField->get_Default() ? String(u"checked") : String(u"unchecked")));
break;
AppendLine(String(u"\tInput format: ") + formField->get_TextInputFormat());
AppendLine(String(u"\tCurrent contents: ") + formField->get_Result());
break;
default:
break;
}
// Let the visitor continue visiting other nodes.
}
String GetText()
{
return mBuilder->ToString();
}
private:
SharedPtr<System::Text::StringBuilder> mBuilder;
void AppendLine(String text)
{
mBuilder->Append(text + u'\n');
}
};

◆ get_IsCheckBoxExactSize()

bool Aspose::Words::Fields::FormField::get_IsCheckBoxExactSize ( )

Gets or sets the boolean value that indicates whether the size of the textbox is automatic or specified explicitly.

Applicable for a check box form field only.

See also
Aspose::Words::Fields::FormField::get_CheckBoxSize
Examples

Shows how insert different kinds of form fields into a document, and process them with using a document visitor implementation.

void Visitor()
{
auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Use a document builder to insert a combo box.
builder->Write(u"Choose a value from this combo box: ");
SharedPtr<FormField> comboBox = builder->InsertComboBox(u"MyComboBox", MakeArray<String>({u"One", u"Two", u"Three"}), 0);
comboBox->set_CalculateOnExit(true);
ASSERT_EQ(3, comboBox->get_DropDownItems()->get_Count());
ASSERT_EQ(0, comboBox->get_DropDownSelectedIndex());
ASSERT_TRUE(comboBox->get_Enabled());
builder->InsertBreak(BreakType::ParagraphBreak);
// Use a document builder to insert a check box.
builder->Write(u"Click this check box to tick/untick it: ");
SharedPtr<FormField> checkBox = builder->InsertCheckBox(u"MyCheckBox", false, 50);
checkBox->set_IsCheckBoxExactSize(true);
checkBox->set_HelpText(u"Right click to check this box");
checkBox->set_OwnHelp(true);
checkBox->set_StatusText(u"Checkbox status text");
checkBox->set_OwnStatus(true);
ASPOSE_ASSERT_EQ(50.0, checkBox->get_CheckBoxSize());
ASSERT_FALSE(checkBox->get_Checked());
ASSERT_FALSE(checkBox->get_Default());
builder->InsertBreak(BreakType::ParagraphBreak);
// Use a document builder to insert text input form field.
builder->Write(u"Enter text here: ");
SharedPtr<FormField> textInput = builder->InsertTextInput(u"MyTextInput", TextFormFieldType::Regular, u"", u"Placeholder text", 50);
textInput->set_EntryMacro(u"EntryMacro");
textInput->set_ExitMacro(u"ExitMacro");
textInput->set_TextInputDefault(u"Regular");
textInput->set_TextInputFormat(u"FIRST CAPITAL");
textInput->SetTextInputValue(System::ObjectExt::Box<String>(u"New placeholder text"));
ASSERT_EQ(TextFormFieldType::Regular, textInput->get_TextInputType());
ASSERT_EQ(50, textInput->get_MaxLength());
// This collection contains all our form fields.
SharedPtr<FormFieldCollection> formFields = doc->get_Range()->get_FormFields();
ASSERT_EQ(3, formFields->get_Count());
// Fields display our form fields. We can see their field codes by opening this document
// in Microsoft and pressing Alt + F9. These fields have no switches,
// and members of the FormField object fully govern their form fields' content.
ASSERT_EQ(3, doc->get_Range()->get_Fields()->get_Count());
ASSERT_EQ(u" FORMDROPDOWN \u0001", doc->get_Range()->get_Fields()->idx_get(0)->GetFieldCode());
ASSERT_EQ(u" FORMCHECKBOX \u0001", doc->get_Range()->get_Fields()->idx_get(1)->GetFieldCode());
ASSERT_EQ(u" FORMTEXT \u0001", doc->get_Range()->get_Fields()->idx_get(2)->GetFieldCode());
// Allow each form field to accept a document visitor.
auto formFieldVisitor = MakeObject<ExFormFields::FormFieldVisitor>();
{
SharedPtr<System::Collections::Generic::IEnumerator<SharedPtr<FormField>>> fieldEnumerator = formFields->GetEnumerator();
while (fieldEnumerator->MoveNext())
{
fieldEnumerator->get_Current()->Accept(formFieldVisitor);
}
}
std::cout << formFieldVisitor->GetText() << std::endl;
doc->UpdateFields();
doc->Save(ArtifactsDir + u"FormFields.Visitor.html");
}
class FormFieldVisitor : public DocumentVisitor
{
public:
FormFieldVisitor()
{
mBuilder = MakeObject<System::Text::StringBuilder>();
}
VisitorAction VisitFormField(SharedPtr<FormField> formField) override
{
AppendLine(System::ObjectExt::ToString(formField->get_Type()) + u": \"" + formField->get_Name() + u"\"");
AppendLine(String(u"\tStatus: ") + (formField->get_Enabled() ? String(u"Enabled") : String(u"Disabled")));
AppendLine(String(u"\tHelp Text: ") + formField->get_HelpText());
AppendLine(String(u"\tEntry macro name: ") + formField->get_EntryMacro());
AppendLine(String(u"\tExit macro name: ") + formField->get_ExitMacro());
switch (formField->get_Type())
{
AppendLine(String(u"\tDrop-down items count: ") + formField->get_DropDownItems()->get_Count() + u", default selected item index: " +
formField->get_DropDownSelectedIndex());
AppendLine(String(u"\tDrop-down items: ") + String::Join(u", ", formField->get_DropDownItems()->LINQ_ToArray()));
break;
AppendLine(String(u"\tCheckbox size: ") + formField->get_CheckBoxSize());
AppendLine(String(u"\t") + u"Checkbox is currently: " + (formField->get_Checked() ? String(u"checked, ") : String(u"unchecked, ")) +
u"by default: " + (formField->get_Default() ? String(u"checked") : String(u"unchecked")));
break;
AppendLine(String(u"\tInput format: ") + formField->get_TextInputFormat());
AppendLine(String(u"\tCurrent contents: ") + formField->get_Result());
break;
default:
break;
}
// Let the visitor continue visiting other nodes.
}
String GetText()
{
return mBuilder->ToString();
}
private:
SharedPtr<System::Text::StringBuilder> mBuilder;
void AppendLine(String text)
{
mBuilder->Append(text + u'\n');
}
};

◆ get_MaxLength()

int32_t Aspose::Words::Fields::FormField::get_MaxLength ( )

Maximum length for the text field. Zero when the length is not limited.

Examples

Shows how insert different kinds of form fields into a document, and process them with using a document visitor implementation.

void Visitor()
{
auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Use a document builder to insert a combo box.
builder->Write(u"Choose a value from this combo box: ");
SharedPtr<FormField> comboBox = builder->InsertComboBox(u"MyComboBox", MakeArray<String>({u"One", u"Two", u"Three"}), 0);
comboBox->set_CalculateOnExit(true);
ASSERT_EQ(3, comboBox->get_DropDownItems()->get_Count());
ASSERT_EQ(0, comboBox->get_DropDownSelectedIndex());
ASSERT_TRUE(comboBox->get_Enabled());
builder->InsertBreak(BreakType::ParagraphBreak);
// Use a document builder to insert a check box.
builder->Write(u"Click this check box to tick/untick it: ");
SharedPtr<FormField> checkBox = builder->InsertCheckBox(u"MyCheckBox", false, 50);
checkBox->set_IsCheckBoxExactSize(true);
checkBox->set_HelpText(u"Right click to check this box");
checkBox->set_OwnHelp(true);
checkBox->set_StatusText(u"Checkbox status text");
checkBox->set_OwnStatus(true);
ASPOSE_ASSERT_EQ(50.0, checkBox->get_CheckBoxSize());
ASSERT_FALSE(checkBox->get_Checked());
ASSERT_FALSE(checkBox->get_Default());
builder->InsertBreak(BreakType::ParagraphBreak);
// Use a document builder to insert text input form field.
builder->Write(u"Enter text here: ");
SharedPtr<FormField> textInput = builder->InsertTextInput(u"MyTextInput", TextFormFieldType::Regular, u"", u"Placeholder text", 50);
textInput->set_EntryMacro(u"EntryMacro");
textInput->set_ExitMacro(u"ExitMacro");
textInput->set_TextInputDefault(u"Regular");
textInput->set_TextInputFormat(u"FIRST CAPITAL");
textInput->SetTextInputValue(System::ObjectExt::Box<String>(u"New placeholder text"));
ASSERT_EQ(TextFormFieldType::Regular, textInput->get_TextInputType());
ASSERT_EQ(50, textInput->get_MaxLength());
// This collection contains all our form fields.
SharedPtr<FormFieldCollection> formFields = doc->get_Range()->get_FormFields();
ASSERT_EQ(3, formFields->get_Count());
// Fields display our form fields. We can see their field codes by opening this document
// in Microsoft and pressing Alt + F9. These fields have no switches,
// and members of the FormField object fully govern their form fields' content.
ASSERT_EQ(3, doc->get_Range()->get_Fields()->get_Count());
ASSERT_EQ(u" FORMDROPDOWN \u0001", doc->get_Range()->get_Fields()->idx_get(0)->GetFieldCode());
ASSERT_EQ(u" FORMCHECKBOX \u0001", doc->get_Range()->get_Fields()->idx_get(1)->GetFieldCode());
ASSERT_EQ(u" FORMTEXT \u0001", doc->get_Range()->get_Fields()->idx_get(2)->GetFieldCode());
// Allow each form field to accept a document visitor.
auto formFieldVisitor = MakeObject<ExFormFields::FormFieldVisitor>();
{
SharedPtr<System::Collections::Generic::IEnumerator<SharedPtr<FormField>>> fieldEnumerator = formFields->GetEnumerator();
while (fieldEnumerator->MoveNext())
{
fieldEnumerator->get_Current()->Accept(formFieldVisitor);
}
}
std::cout << formFieldVisitor->GetText() << std::endl;
doc->UpdateFields();
doc->Save(ArtifactsDir + u"FormFields.Visitor.html");
}
class FormFieldVisitor : public DocumentVisitor
{
public:
FormFieldVisitor()
{
mBuilder = MakeObject<System::Text::StringBuilder>();
}
VisitorAction VisitFormField(SharedPtr<FormField> formField) override
{
AppendLine(System::ObjectExt::ToString(formField->get_Type()) + u": \"" + formField->get_Name() + u"\"");
AppendLine(String(u"\tStatus: ") + (formField->get_Enabled() ? String(u"Enabled") : String(u"Disabled")));
AppendLine(String(u"\tHelp Text: ") + formField->get_HelpText());
AppendLine(String(u"\tEntry macro name: ") + formField->get_EntryMacro());
AppendLine(String(u"\tExit macro name: ") + formField->get_ExitMacro());
switch (formField->get_Type())
{
AppendLine(String(u"\tDrop-down items count: ") + formField->get_DropDownItems()->get_Count() + u", default selected item index: " +
formField->get_DropDownSelectedIndex());
AppendLine(String(u"\tDrop-down items: ") + String::Join(u", ", formField->get_DropDownItems()->LINQ_ToArray()));
break;
AppendLine(String(u"\tCheckbox size: ") + formField->get_CheckBoxSize());
AppendLine(String(u"\t") + u"Checkbox is currently: " + (formField->get_Checked() ? String(u"checked, ") : String(u"unchecked, ")) +
u"by default: " + (formField->get_Default() ? String(u"checked") : String(u"unchecked")));
break;
AppendLine(String(u"\tInput format: ") + formField->get_TextInputFormat());
AppendLine(String(u"\tCurrent contents: ") + formField->get_Result());
break;
default:
break;
}
// Let the visitor continue visiting other nodes.
}
String GetText()
{
return mBuilder->ToString();
}
private:
SharedPtr<System::Text::StringBuilder> mBuilder;
void AppendLine(String text)
{
mBuilder->Append(text + u'\n');
}
};

◆ get_Name()

System::String Aspose::Words::Fields::FormField::get_Name ( )

Gets or sets the form field name.

Examples

Shows how to insert a combo box.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
builder->Write(u"Please select a fruit: ");
// Insert a combo box which will allow a user to choose an option from a collection of strings.
SharedPtr<FormField> comboBox = builder->InsertComboBox(u"MyComboBox", MakeArray<String>({u"Apple", u"Banana", u"Cherry"}), 0);
ASSERT_EQ(u"MyComboBox", comboBox->get_Name());
ASSERT_EQ(FieldType::FieldFormDropDown, comboBox->get_Type());
ASSERT_EQ(u"Apple", comboBox->get_Result());
// The form field will appear in the form of a "select" html tag.
doc->Save(ArtifactsDir + u"FormFields.Create.html");

◆ get_NodeType()

Aspose::Words::NodeType Aspose::Words::Fields::FormField::get_NodeType ( ) const
overridevirtual

Returns NodeType.FormField.

Examples

Shows how to traverse a composite node's tree of child nodes.

void RecurseChildren()
{
auto doc = MakeObject<Document>(MyDir + u"Paragraphs.docx");
// Any node that can contain child nodes, such as the document itself, is composite.
ASSERT_TRUE(doc->get_IsComposite());
// Invoke the recursive function that will go through and print all the child nodes of a composite node.
TraverseAllNodes(doc, 0);
}
void TraverseAllNodes(SharedPtr<CompositeNode> parentNode, int depth)
{
for (SharedPtr<Node> childNode = parentNode->get_FirstChild(); childNode != nullptr; childNode = childNode->get_NextSibling())
{
std::cout << (String(u'\t', depth)) << Node::NodeTypeToString(childNode->get_NodeType());
// Recurse into the node if it is a composite node. Otherwise, print its contents if it is an inline node.
if (childNode->get_IsComposite())
{
std::cout << std::endl;
TraverseAllNodes(System::DynamicCast<CompositeNode>(childNode), depth + 1);
}
else if (System::ObjectExt::Is<Inline>(childNode))
{
std::cout << " - \"" << childNode->GetText().Trim() << "\"" << std::endl;
}
else
{
std::cout << std::endl;
}
}
}

Implements Aspose::Words::Node.

◆ get_OwnHelp()

bool Aspose::Words::Fields::FormField::get_OwnHelp ( )

Specifies the source of the text that's displayed in a message box when a form field has the focus and the user presses F1.

If True, the text specified by the HelpText property is displayed. If False, the text in the AutoText entry specified by the HelpText property is displayed.

Examples

Shows how insert different kinds of form fields into a document, and process them with using a document visitor implementation.

void Visitor()
{
auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Use a document builder to insert a combo box.
builder->Write(u"Choose a value from this combo box: ");
SharedPtr<FormField> comboBox = builder->InsertComboBox(u"MyComboBox", MakeArray<String>({u"One", u"Two", u"Three"}), 0);
comboBox->set_CalculateOnExit(true);
ASSERT_EQ(3, comboBox->get_DropDownItems()->get_Count());
ASSERT_EQ(0, comboBox->get_DropDownSelectedIndex());
ASSERT_TRUE(comboBox->get_Enabled());
builder->InsertBreak(BreakType::ParagraphBreak);
// Use a document builder to insert a check box.
builder->Write(u"Click this check box to tick/untick it: ");
SharedPtr<FormField> checkBox = builder->InsertCheckBox(u"MyCheckBox", false, 50);
checkBox->set_IsCheckBoxExactSize(true);
checkBox->set_HelpText(u"Right click to check this box");
checkBox->set_OwnHelp(true);
checkBox->set_StatusText(u"Checkbox status text");
checkBox->set_OwnStatus(true);
ASPOSE_ASSERT_EQ(50.0, checkBox->get_CheckBoxSize());
ASSERT_FALSE(checkBox->get_Checked());
ASSERT_FALSE(checkBox->get_Default());
builder->InsertBreak(BreakType::ParagraphBreak);
// Use a document builder to insert text input form field.
builder->Write(u"Enter text here: ");
SharedPtr<FormField> textInput = builder->InsertTextInput(u"MyTextInput", TextFormFieldType::Regular, u"", u"Placeholder text", 50);
textInput->set_EntryMacro(u"EntryMacro");
textInput->set_ExitMacro(u"ExitMacro");
textInput->set_TextInputDefault(u"Regular");
textInput->set_TextInputFormat(u"FIRST CAPITAL");
textInput->SetTextInputValue(System::ObjectExt::Box<String>(u"New placeholder text"));
ASSERT_EQ(TextFormFieldType::Regular, textInput->get_TextInputType());
ASSERT_EQ(50, textInput->get_MaxLength());
// This collection contains all our form fields.
SharedPtr<FormFieldCollection> formFields = doc->get_Range()->get_FormFields();
ASSERT_EQ(3, formFields->get_Count());
// Fields display our form fields. We can see their field codes by opening this document
// in Microsoft and pressing Alt + F9. These fields have no switches,
// and members of the FormField object fully govern their form fields' content.
ASSERT_EQ(3, doc->get_Range()->get_Fields()->get_Count());
ASSERT_EQ(u" FORMDROPDOWN \u0001", doc->get_Range()->get_Fields()->idx_get(0)->GetFieldCode());
ASSERT_EQ(u" FORMCHECKBOX \u0001", doc->get_Range()->get_Fields()->idx_get(1)->GetFieldCode());
ASSERT_EQ(u" FORMTEXT \u0001", doc->get_Range()->get_Fields()->idx_get(2)->GetFieldCode());
// Allow each form field to accept a document visitor.
auto formFieldVisitor = MakeObject<ExFormFields::FormFieldVisitor>();
{
SharedPtr<System::Collections::Generic::IEnumerator<SharedPtr<FormField>>> fieldEnumerator = formFields->GetEnumerator();
while (fieldEnumerator->MoveNext())
{
fieldEnumerator->get_Current()->Accept(formFieldVisitor);
}
}
std::cout << formFieldVisitor->GetText() << std::endl;
doc->UpdateFields();
doc->Save(ArtifactsDir + u"FormFields.Visitor.html");
}
class FormFieldVisitor : public DocumentVisitor
{
public:
FormFieldVisitor()
{
mBuilder = MakeObject<System::Text::StringBuilder>();
}
VisitorAction VisitFormField(SharedPtr<FormField> formField) override
{
AppendLine(System::ObjectExt::ToString(formField->get_Type()) + u": \"" + formField->get_Name() + u"\"");
AppendLine(String(u"\tStatus: ") + (formField->get_Enabled() ? String(u"Enabled") : String(u"Disabled")));
AppendLine(String(u"\tHelp Text: ") + formField->get_HelpText());
AppendLine(String(u"\tEntry macro name: ") + formField->get_EntryMacro());
AppendLine(String(u"\tExit macro name: ") + formField->get_ExitMacro());
switch (formField->get_Type())
{
AppendLine(String(u"\tDrop-down items count: ") + formField->get_DropDownItems()->get_Count() + u", default selected item index: " +
formField->get_DropDownSelectedIndex());
AppendLine(String(u"\tDrop-down items: ") + String::Join(u", ", formField->get_DropDownItems()->LINQ_ToArray()));
break;
AppendLine(String(u"\tCheckbox size: ") + formField->get_CheckBoxSize());
AppendLine(String(u"\t") + u"Checkbox is currently: " + (formField->get_Checked() ? String(u"checked, ") : String(u"unchecked, ")) +
u"by default: " + (formField->get_Default() ? String(u"checked") : String(u"unchecked")));
break;
AppendLine(String(u"\tInput format: ") + formField->get_TextInputFormat());
AppendLine(String(u"\tCurrent contents: ") + formField->get_Result());
break;
default:
break;
}
// Let the visitor continue visiting other nodes.
}
String GetText()
{
return mBuilder->ToString();
}
private:
SharedPtr<System::Text::StringBuilder> mBuilder;
void AppendLine(String text)
{
mBuilder->Append(text + u'\n');
}
};

◆ get_OwnStatus()

bool Aspose::Words::Fields::FormField::get_OwnStatus ( )

Specifies the source of the text that's displayed in the status bar when a form field has the focus.

If true, the text specified by the StatusText property is displayed. If false, the text of the AutoText entry specified by the StatusText property is displayed.

Examples

Shows how insert different kinds of form fields into a document, and process them with using a document visitor implementation.

void Visitor()
{
auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Use a document builder to insert a combo box.
builder->Write(u"Choose a value from this combo box: ");
SharedPtr<FormField> comboBox = builder->InsertComboBox(u"MyComboBox", MakeArray<String>({u"One", u"Two", u"Three"}), 0);
comboBox->set_CalculateOnExit(true);
ASSERT_EQ(3, comboBox->get_DropDownItems()->get_Count());
ASSERT_EQ(0, comboBox->get_DropDownSelectedIndex());
ASSERT_TRUE(comboBox->get_Enabled());
builder->InsertBreak(BreakType::ParagraphBreak);
// Use a document builder to insert a check box.
builder->Write(u"Click this check box to tick/untick it: ");
SharedPtr<FormField> checkBox = builder->InsertCheckBox(u"MyCheckBox", false, 50);
checkBox->set_IsCheckBoxExactSize(true);
checkBox->set_HelpText(u"Right click to check this box");
checkBox->set_OwnHelp(true);
checkBox->set_StatusText(u"Checkbox status text");
checkBox->set_OwnStatus(true);
ASPOSE_ASSERT_EQ(50.0, checkBox->get_CheckBoxSize());
ASSERT_FALSE(checkBox->get_Checked());
ASSERT_FALSE(checkBox->get_Default());
builder->InsertBreak(BreakType::ParagraphBreak);
// Use a document builder to insert text input form field.
builder->Write(u"Enter text here: ");
SharedPtr<FormField> textInput = builder->InsertTextInput(u"MyTextInput", TextFormFieldType::Regular, u"", u"Placeholder text", 50);
textInput->set_EntryMacro(u"EntryMacro");
textInput->set_ExitMacro(u"ExitMacro");
textInput->set_TextInputDefault(u"Regular");
textInput->set_TextInputFormat(u"FIRST CAPITAL");
textInput->SetTextInputValue(System::ObjectExt::Box<String>(u"New placeholder text"));
ASSERT_EQ(TextFormFieldType::Regular, textInput->get_TextInputType());
ASSERT_EQ(50, textInput->get_MaxLength());
// This collection contains all our form fields.
SharedPtr<FormFieldCollection> formFields = doc->get_Range()->get_FormFields();
ASSERT_EQ(3, formFields->get_Count());
// Fields display our form fields. We can see their field codes by opening this document
// in Microsoft and pressing Alt + F9. These fields have no switches,
// and members of the FormField object fully govern their form fields' content.
ASSERT_EQ(3, doc->get_Range()->get_Fields()->get_Count());
ASSERT_EQ(u" FORMDROPDOWN \u0001", doc->get_Range()->get_Fields()->idx_get(0)->GetFieldCode());
ASSERT_EQ(u" FORMCHECKBOX \u0001", doc->get_Range()->get_Fields()->idx_get(1)->GetFieldCode());
ASSERT_EQ(u" FORMTEXT \u0001", doc->get_Range()->get_Fields()->idx_get(2)->GetFieldCode());
// Allow each form field to accept a document visitor.
auto formFieldVisitor = MakeObject<ExFormFields::FormFieldVisitor>();
{
SharedPtr<System::Collections::Generic::IEnumerator<SharedPtr<FormField>>> fieldEnumerator = formFields->GetEnumerator();
while (fieldEnumerator->MoveNext())
{
fieldEnumerator->get_Current()->Accept(formFieldVisitor);
}
}
std::cout << formFieldVisitor->GetText() << std::endl;
doc->UpdateFields();
doc->Save(ArtifactsDir + u"FormFields.Visitor.html");
}
class FormFieldVisitor : public DocumentVisitor
{
public:
FormFieldVisitor()
{
mBuilder = MakeObject<System::Text::StringBuilder>();
}
VisitorAction VisitFormField(SharedPtr<FormField> formField) override
{
AppendLine(System::ObjectExt::ToString(formField->get_Type()) + u": \"" + formField->get_Name() + u"\"");
AppendLine(String(u"\tStatus: ") + (formField->get_Enabled() ? String(u"Enabled") : String(u"Disabled")));
AppendLine(String(u"\tHelp Text: ") + formField->get_HelpText());
AppendLine(String(u"\tEntry macro name: ") + formField->get_EntryMacro());
AppendLine(String(u"\tExit macro name: ") + formField->get_ExitMacro());
switch (formField->get_Type())
{
AppendLine(String(u"\tDrop-down items count: ") + formField->get_DropDownItems()->get_Count() + u", default selected item index: " +
formField->get_DropDownSelectedIndex());
AppendLine(String(u"\tDrop-down items: ") + String::Join(u", ", formField->get_DropDownItems()->LINQ_ToArray()));
break;
AppendLine(String(u"\tCheckbox size: ") + formField->get_CheckBoxSize());
AppendLine(String(u"\t") + u"Checkbox is currently: " + (formField->get_Checked() ? String(u"checked, ") : String(u"unchecked, ")) +
u"by default: " + (formField->get_Default() ? String(u"checked") : String(u"unchecked")));
break;
AppendLine(String(u"\tInput format: ") + formField->get_TextInputFormat());
AppendLine(String(u"\tCurrent contents: ") + formField->get_Result());
break;
default:
break;
}
// Let the visitor continue visiting other nodes.
}
String GetText()
{
return mBuilder->ToString();
}
private:
SharedPtr<System::Text::StringBuilder> mBuilder;
void AppendLine(String text)
{
mBuilder->Append(text + u'\n');
}
};

◆ get_Result()

System::String Aspose::Words::Fields::FormField::get_Result ( )

Gets or sets a string that represents the result of this form field.

For a text form field the result is the text that is in the field.

For a checkbox form field the result can be "1" or "0" to indicate checked or unchecked.

For a dropdown form field the result is the string selected in the dropdown.

Setting Result for a text form field does not apply the text format specified in TextInputFormat. If you want to set a value and apply the format, use the SetTextInputValue() method.

For a text form field the TextInputDefault value is applied if value is null.

Examples

Shows how to insert a combo box.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
builder->Write(u"Please select a fruit: ");
// Insert a combo box which will allow a user to choose an option from a collection of strings.
SharedPtr<FormField> comboBox = builder->InsertComboBox(u"MyComboBox", MakeArray<String>({u"Apple", u"Banana", u"Cherry"}), 0);
ASSERT_EQ(u"MyComboBox", comboBox->get_Name());
ASSERT_EQ(FieldType::FieldFormDropDown, comboBox->get_Type());
ASSERT_EQ(u"Apple", comboBox->get_Result());
// The form field will appear in the form of a "select" html tag.
doc->Save(ArtifactsDir + u"FormFields.Create.html");

◆ get_StatusText()

System::String Aspose::Words::Fields::FormField::get_StatusText ( )

Returns or sets the text that's displayed in the status bar when a form field has the focus.

If the OwnStatus property is set to true, the StatusText property specifies the status bar text. If the OwnStatus property is set to false, the StatusText property specifies the name of an AutoText entry that contains status bar text for the form field.

Microsoft Word allows strings with at most 138 characters.

Examples

Shows how insert different kinds of form fields into a document, and process them with using a document visitor implementation.

void Visitor()
{
auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Use a document builder to insert a combo box.
builder->Write(u"Choose a value from this combo box: ");
SharedPtr<FormField> comboBox = builder->InsertComboBox(u"MyComboBox", MakeArray<String>({u"One", u"Two", u"Three"}), 0);
comboBox->set_CalculateOnExit(true);
ASSERT_EQ(3, comboBox->get_DropDownItems()->get_Count());
ASSERT_EQ(0, comboBox->get_DropDownSelectedIndex());
ASSERT_TRUE(comboBox->get_Enabled());
builder->InsertBreak(BreakType::ParagraphBreak);
// Use a document builder to insert a check box.
builder->Write(u"Click this check box to tick/untick it: ");
SharedPtr<FormField> checkBox = builder->InsertCheckBox(u"MyCheckBox", false, 50);
checkBox->set_IsCheckBoxExactSize(true);
checkBox->set_HelpText(u"Right click to check this box");
checkBox->set_OwnHelp(true);
checkBox->set_StatusText(u"Checkbox status text");
checkBox->set_OwnStatus(true);
ASPOSE_ASSERT_EQ(50.0, checkBox->get_CheckBoxSize());
ASSERT_FALSE(checkBox->get_Checked());
ASSERT_FALSE(checkBox->get_Default());
builder->InsertBreak(BreakType::ParagraphBreak);
// Use a document builder to insert text input form field.
builder->Write(u"Enter text here: ");
SharedPtr<FormField> textInput = builder->InsertTextInput(u"MyTextInput", TextFormFieldType::Regular, u"", u"Placeholder text", 50);
textInput->set_EntryMacro(u"EntryMacro");
textInput->set_ExitMacro(u"ExitMacro");
textInput->set_TextInputDefault(u"Regular");
textInput->set_TextInputFormat(u"FIRST CAPITAL");
textInput->SetTextInputValue(System::ObjectExt::Box<String>(u"New placeholder text"));
ASSERT_EQ(TextFormFieldType::Regular, textInput->get_TextInputType());
ASSERT_EQ(50, textInput->get_MaxLength());
// This collection contains all our form fields.
SharedPtr<FormFieldCollection> formFields = doc->get_Range()->get_FormFields();
ASSERT_EQ(3, formFields->get_Count());
// Fields display our form fields. We can see their field codes by opening this document
// in Microsoft and pressing Alt + F9. These fields have no switches,
// and members of the FormField object fully govern their form fields' content.
ASSERT_EQ(3, doc->get_Range()->get_Fields()->get_Count());
ASSERT_EQ(u" FORMDROPDOWN \u0001", doc->get_Range()->get_Fields()->idx_get(0)->GetFieldCode());
ASSERT_EQ(u" FORMCHECKBOX \u0001", doc->get_Range()->get_Fields()->idx_get(1)->GetFieldCode());
ASSERT_EQ(u" FORMTEXT \u0001", doc->get_Range()->get_Fields()->idx_get(2)->GetFieldCode());
// Allow each form field to accept a document visitor.
auto formFieldVisitor = MakeObject<ExFormFields::FormFieldVisitor>();
{
SharedPtr<System::Collections::Generic::IEnumerator<SharedPtr<FormField>>> fieldEnumerator = formFields->GetEnumerator();
while (fieldEnumerator->MoveNext())
{
fieldEnumerator->get_Current()->Accept(formFieldVisitor);
}
}
std::cout << formFieldVisitor->GetText() << std::endl;
doc->UpdateFields();
doc->Save(ArtifactsDir + u"FormFields.Visitor.html");
}
class FormFieldVisitor : public DocumentVisitor
{
public:
FormFieldVisitor()
{
mBuilder = MakeObject<System::Text::StringBuilder>();
}
VisitorAction VisitFormField(SharedPtr<FormField> formField) override
{
AppendLine(System::ObjectExt::ToString(formField->get_Type()) + u": \"" + formField->get_Name() + u"\"");
AppendLine(String(u"\tStatus: ") + (formField->get_Enabled() ? String(u"Enabled") : String(u"Disabled")));
AppendLine(String(u"\tHelp Text: ") + formField->get_HelpText());
AppendLine(String(u"\tEntry macro name: ") + formField->get_EntryMacro());
AppendLine(String(u"\tExit macro name: ") + formField->get_ExitMacro());
switch (formField->get_Type())
{
AppendLine(String(u"\tDrop-down items count: ") + formField->get_DropDownItems()->get_Count() + u", default selected item index: " +
formField->get_DropDownSelectedIndex());
AppendLine(String(u"\tDrop-down items: ") + String::Join(u", ", formField->get_DropDownItems()->LINQ_ToArray()));
break;
AppendLine(String(u"\tCheckbox size: ") + formField->get_CheckBoxSize());
AppendLine(String(u"\t") + u"Checkbox is currently: " + (formField->get_Checked() ? String(u"checked, ") : String(u"unchecked, ")) +
u"by default: " + (formField->get_Default() ? String(u"checked") : String(u"unchecked")));
break;
AppendLine(String(u"\tInput format: ") + formField->get_TextInputFormat());
AppendLine(String(u"\tCurrent contents: ") + formField->get_Result());
break;
default:
break;
}
// Let the visitor continue visiting other nodes.
}
String GetText()
{
return mBuilder->ToString();
}
private:
SharedPtr<System::Text::StringBuilder> mBuilder;
void AppendLine(String text)
{
mBuilder->Append(text + u'\n');
}
};

◆ get_TextInputDefault()

System::String Aspose::Words::Fields::FormField::get_TextInputDefault ( )

Gets or sets the default string or a calculation expression of a text form field.

The meaning of this property depends on the value of the TextInputType property.

When TextInputType is Regular or Number, this string specifies the default string for the text form field. This string is the content that Microsoft Word will display in the document when the form field is empty.

When TextInputType is Calculated, then this string holds the expression to be calculated. The expression needs to be a formula valid according to Microsoft Word formula field requirements. When you set a new expression using this property, Aspose.Words calculates the formula result automatically and inserts it into the form field.

Microsoft Word allows strings with at most 255 characters.

Examples

Shows how insert different kinds of form fields into a document, and process them with using a document visitor implementation.

void Visitor()
{
auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Use a document builder to insert a combo box.
builder->Write(u"Choose a value from this combo box: ");
SharedPtr<FormField> comboBox = builder->InsertComboBox(u"MyComboBox", MakeArray<String>({u"One", u"Two", u"Three"}), 0);
comboBox->set_CalculateOnExit(true);
ASSERT_EQ(3, comboBox->get_DropDownItems()->get_Count());
ASSERT_EQ(0, comboBox->get_DropDownSelectedIndex());
ASSERT_TRUE(comboBox->get_Enabled());
builder->InsertBreak(BreakType::ParagraphBreak);
// Use a document builder to insert a check box.
builder->Write(u"Click this check box to tick/untick it: ");
SharedPtr<FormField> checkBox = builder->InsertCheckBox(u"MyCheckBox", false, 50);
checkBox->set_IsCheckBoxExactSize(true);
checkBox->set_HelpText(u"Right click to check this box");
checkBox->set_OwnHelp(true);
checkBox->set_StatusText(u"Checkbox status text");
checkBox->set_OwnStatus(true);
ASPOSE_ASSERT_EQ(50.0, checkBox->get_CheckBoxSize());
ASSERT_FALSE(checkBox->get_Checked());
ASSERT_FALSE(checkBox->get_Default());
builder->InsertBreak(BreakType::ParagraphBreak);
// Use a document builder to insert text input form field.
builder->Write(u"Enter text here: ");
SharedPtr<FormField> textInput = builder->InsertTextInput(u"MyTextInput", TextFormFieldType::Regular, u"", u"Placeholder text", 50);
textInput->set_EntryMacro(u"EntryMacro");
textInput->set_ExitMacro(u"ExitMacro");
textInput->set_TextInputDefault(u"Regular");
textInput->set_TextInputFormat(u"FIRST CAPITAL");
textInput->SetTextInputValue(System::ObjectExt::Box<String>(u"New placeholder text"));
ASSERT_EQ(TextFormFieldType::Regular, textInput->get_TextInputType());
ASSERT_EQ(50, textInput->get_MaxLength());
// This collection contains all our form fields.
SharedPtr<FormFieldCollection> formFields = doc->get_Range()->get_FormFields();
ASSERT_EQ(3, formFields->get_Count());
// Fields display our form fields. We can see their field codes by opening this document
// in Microsoft and pressing Alt + F9. These fields have no switches,
// and members of the FormField object fully govern their form fields' content.
ASSERT_EQ(3, doc->get_Range()->get_Fields()->get_Count());
ASSERT_EQ(u" FORMDROPDOWN \u0001", doc->get_Range()->get_Fields()->idx_get(0)->GetFieldCode());
ASSERT_EQ(u" FORMCHECKBOX \u0001", doc->get_Range()->get_Fields()->idx_get(1)->GetFieldCode());
ASSERT_EQ(u" FORMTEXT \u0001", doc->get_Range()->get_Fields()->idx_get(2)->GetFieldCode());
// Allow each form field to accept a document visitor.
auto formFieldVisitor = MakeObject<ExFormFields::FormFieldVisitor>();
{
SharedPtr<System::Collections::Generic::IEnumerator<SharedPtr<FormField>>> fieldEnumerator = formFields->GetEnumerator();
while (fieldEnumerator->MoveNext())
{
fieldEnumerator->get_Current()->Accept(formFieldVisitor);
}
}
std::cout << formFieldVisitor->GetText() << std::endl;
doc->UpdateFields();
doc->Save(ArtifactsDir + u"FormFields.Visitor.html");
}
class FormFieldVisitor : public DocumentVisitor
{
public:
FormFieldVisitor()
{
mBuilder = MakeObject<System::Text::StringBuilder>();
}
VisitorAction VisitFormField(SharedPtr<FormField> formField) override
{
AppendLine(System::ObjectExt::ToString(formField->get_Type()) + u": \"" + formField->get_Name() + u"\"");
AppendLine(String(u"\tStatus: ") + (formField->get_Enabled() ? String(u"Enabled") : String(u"Disabled")));
AppendLine(String(u"\tHelp Text: ") + formField->get_HelpText());
AppendLine(String(u"\tEntry macro name: ") + formField->get_EntryMacro());
AppendLine(String(u"\tExit macro name: ") + formField->get_ExitMacro());
switch (formField->get_Type())
{
AppendLine(String(u"\tDrop-down items count: ") + formField->get_DropDownItems()->get_Count() + u", default selected item index: " +
formField->get_DropDownSelectedIndex());
AppendLine(String(u"\tDrop-down items: ") + String::Join(u", ", formField->get_DropDownItems()->LINQ_ToArray()));
break;
AppendLine(String(u"\tCheckbox size: ") + formField->get_CheckBoxSize());
AppendLine(String(u"\t") + u"Checkbox is currently: " + (formField->get_Checked() ? String(u"checked, ") : String(u"unchecked, ")) +
u"by default: " + (formField->get_Default() ? String(u"checked") : String(u"unchecked")));
break;
AppendLine(String(u"\tInput format: ") + formField->get_TextInputFormat());
AppendLine(String(u"\tCurrent contents: ") + formField->get_Result());
break;
default:
break;
}
// Let the visitor continue visiting other nodes.
}
String GetText()
{
return mBuilder->ToString();
}
private:
SharedPtr<System::Text::StringBuilder> mBuilder;
void AppendLine(String text)
{
mBuilder->Append(text + u'\n');
}
};

◆ get_TextInputFormat()

System::String Aspose::Words::Fields::FormField::get_TextInputFormat ( )

Returns or sets the text formatting for a text form field.

If the text form field contains regular text, then valid format strings are "", "UPPERCASE", "LOWERCASE", "FIRST CAPITAL" and "TITLE CASE". The strings are case-insensitive.

If the text form field contains a number or a date/time value, then valid format strings are number or date and time format strings.

Microsoft Word allows strings with at most 64 characters.

Examples

Shows how insert different kinds of form fields into a document, and process them with using a document visitor implementation.

void Visitor()
{
auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Use a document builder to insert a combo box.
builder->Write(u"Choose a value from this combo box: ");
SharedPtr<FormField> comboBox = builder->InsertComboBox(u"MyComboBox", MakeArray<String>({u"One", u"Two", u"Three"}), 0);
comboBox->set_CalculateOnExit(true);
ASSERT_EQ(3, comboBox->get_DropDownItems()->get_Count());
ASSERT_EQ(0, comboBox->get_DropDownSelectedIndex());
ASSERT_TRUE(comboBox->get_Enabled());
builder->InsertBreak(BreakType::ParagraphBreak);
// Use a document builder to insert a check box.
builder->Write(u"Click this check box to tick/untick it: ");
SharedPtr<FormField> checkBox = builder->InsertCheckBox(u"MyCheckBox", false, 50);
checkBox->set_IsCheckBoxExactSize(true);
checkBox->set_HelpText(u"Right click to check this box");
checkBox->set_OwnHelp(true);
checkBox->set_StatusText(u"Checkbox status text");
checkBox->set_OwnStatus(true);
ASPOSE_ASSERT_EQ(50.0, checkBox->get_CheckBoxSize());
ASSERT_FALSE(checkBox->get_Checked());
ASSERT_FALSE(checkBox->get_Default());
builder->InsertBreak(BreakType::ParagraphBreak);
// Use a document builder to insert text input form field.
builder->Write(u"Enter text here: ");
SharedPtr<FormField> textInput = builder->InsertTextInput(u"MyTextInput", TextFormFieldType::Regular, u"", u"Placeholder text", 50);
textInput->set_EntryMacro(u"EntryMacro");
textInput->set_ExitMacro(u"ExitMacro");
textInput->set_TextInputDefault(u"Regular");
textInput->set_TextInputFormat(u"FIRST CAPITAL");
textInput->SetTextInputValue(System::ObjectExt::Box<String>(u"New placeholder text"));
ASSERT_EQ(TextFormFieldType::Regular, textInput->get_TextInputType());
ASSERT_EQ(50, textInput->get_MaxLength());
// This collection contains all our form fields.
SharedPtr<FormFieldCollection> formFields = doc->get_Range()->get_FormFields();
ASSERT_EQ(3, formFields->get_Count());
// Fields display our form fields. We can see their field codes by opening this document
// in Microsoft and pressing Alt + F9. These fields have no switches,
// and members of the FormField object fully govern their form fields' content.
ASSERT_EQ(3, doc->get_Range()->get_Fields()->get_Count());
ASSERT_EQ(u" FORMDROPDOWN \u0001", doc->get_Range()->get_Fields()->idx_get(0)->GetFieldCode());
ASSERT_EQ(u" FORMCHECKBOX \u0001", doc->get_Range()->get_Fields()->idx_get(1)->GetFieldCode());
ASSERT_EQ(u" FORMTEXT \u0001", doc->get_Range()->get_Fields()->idx_get(2)->GetFieldCode());
// Allow each form field to accept a document visitor.
auto formFieldVisitor = MakeObject<ExFormFields::FormFieldVisitor>();
{
SharedPtr<System::Collections::Generic::IEnumerator<SharedPtr<FormField>>> fieldEnumerator = formFields->GetEnumerator();
while (fieldEnumerator->MoveNext())
{
fieldEnumerator->get_Current()->Accept(formFieldVisitor);
}
}
std::cout << formFieldVisitor->GetText() << std::endl;
doc->UpdateFields();
doc->Save(ArtifactsDir + u"FormFields.Visitor.html");
}
class FormFieldVisitor : public DocumentVisitor
{
public:
FormFieldVisitor()
{
mBuilder = MakeObject<System::Text::StringBuilder>();
}
VisitorAction VisitFormField(SharedPtr<FormField> formField) override
{
AppendLine(System::ObjectExt::ToString(formField->get_Type()) + u": \"" + formField->get_Name() + u"\"");
AppendLine(String(u"\tStatus: ") + (formField->get_Enabled() ? String(u"Enabled") : String(u"Disabled")));
AppendLine(String(u"\tHelp Text: ") + formField->get_HelpText());
AppendLine(String(u"\tEntry macro name: ") + formField->get_EntryMacro());
AppendLine(String(u"\tExit macro name: ") + formField->get_ExitMacro());
switch (formField->get_Type())
{
AppendLine(String(u"\tDrop-down items count: ") + formField->get_DropDownItems()->get_Count() + u", default selected item index: " +
formField->get_DropDownSelectedIndex());
AppendLine(String(u"\tDrop-down items: ") + String::Join(u", ", formField->get_DropDownItems()->LINQ_ToArray()));
break;
AppendLine(String(u"\tCheckbox size: ") + formField->get_CheckBoxSize());
AppendLine(String(u"\t") + u"Checkbox is currently: " + (formField->get_Checked() ? String(u"checked, ") : String(u"unchecked, ")) +
u"by default: " + (formField->get_Default() ? String(u"checked") : String(u"unchecked")));
break;
AppendLine(String(u"\tInput format: ") + formField->get_TextInputFormat());
AppendLine(String(u"\tCurrent contents: ") + formField->get_Result());
break;
default:
break;
}
// Let the visitor continue visiting other nodes.
}
String GetText()
{
return mBuilder->ToString();
}
private:
SharedPtr<System::Text::StringBuilder> mBuilder;
void AppendLine(String text)
{
mBuilder->Append(text + u'\n');
}
};

◆ get_TextInputType()

Aspose::Words::Fields::TextFormFieldType Aspose::Words::Fields::FormField::get_TextInputType ( )

Gets or sets the type of a text form field.

Examples

Shows how insert different kinds of form fields into a document, and process them with using a document visitor implementation.

void Visitor()
{
auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Use a document builder to insert a combo box.
builder->Write(u"Choose a value from this combo box: ");
SharedPtr<FormField> comboBox = builder->InsertComboBox(u"MyComboBox", MakeArray<String>({u"One", u"Two", u"Three"}), 0);
comboBox->set_CalculateOnExit(true);
ASSERT_EQ(3, comboBox->get_DropDownItems()->get_Count());
ASSERT_EQ(0, comboBox->get_DropDownSelectedIndex());
ASSERT_TRUE(comboBox->get_Enabled());
builder->InsertBreak(BreakType::ParagraphBreak);
// Use a document builder to insert a check box.
builder->Write(u"Click this check box to tick/untick it: ");
SharedPtr<FormField> checkBox = builder->InsertCheckBox(u"MyCheckBox", false, 50);
checkBox->set_IsCheckBoxExactSize(true);
checkBox->set_HelpText(u"Right click to check this box");
checkBox->set_OwnHelp(true);
checkBox->set_StatusText(u"Checkbox status text");
checkBox->set_OwnStatus(true);
ASPOSE_ASSERT_EQ(50.0, checkBox->get_CheckBoxSize());
ASSERT_FALSE(checkBox->get_Checked());
ASSERT_FALSE(checkBox->get_Default());
builder->InsertBreak(BreakType::ParagraphBreak);
// Use a document builder to insert text input form field.
builder->Write(u"Enter text here: ");
SharedPtr<FormField> textInput = builder->InsertTextInput(u"MyTextInput", TextFormFieldType::Regular, u"", u"Placeholder text", 50);
textInput->set_EntryMacro(u"EntryMacro");
textInput->set_ExitMacro(u"ExitMacro");
textInput->set_TextInputDefault(u"Regular");
textInput->set_TextInputFormat(u"FIRST CAPITAL");
textInput->SetTextInputValue(System::ObjectExt::Box<String>(u"New placeholder text"));
ASSERT_EQ(TextFormFieldType::Regular, textInput->get_TextInputType());
ASSERT_EQ(50, textInput->get_MaxLength());
// This collection contains all our form fields.
SharedPtr<FormFieldCollection> formFields = doc->get_Range()->get_FormFields();
ASSERT_EQ(3, formFields->get_Count());
// Fields display our form fields. We can see their field codes by opening this document
// in Microsoft and pressing Alt + F9. These fields have no switches,
// and members of the FormField object fully govern their form fields' content.
ASSERT_EQ(3, doc->get_Range()->get_Fields()->get_Count());
ASSERT_EQ(u" FORMDROPDOWN \u0001", doc->get_Range()->get_Fields()->idx_get(0)->GetFieldCode());
ASSERT_EQ(u" FORMCHECKBOX \u0001", doc->get_Range()->get_Fields()->idx_get(1)->GetFieldCode());
ASSERT_EQ(u" FORMTEXT \u0001", doc->get_Range()->get_Fields()->idx_get(2)->GetFieldCode());
// Allow each form field to accept a document visitor.
auto formFieldVisitor = MakeObject<ExFormFields::FormFieldVisitor>();
{
SharedPtr<System::Collections::Generic::IEnumerator<SharedPtr<FormField>>> fieldEnumerator = formFields->GetEnumerator();
while (fieldEnumerator->MoveNext())
{
fieldEnumerator->get_Current()->Accept(formFieldVisitor);
}
}
std::cout << formFieldVisitor->GetText() << std::endl;
doc->UpdateFields();
doc->Save(ArtifactsDir + u"FormFields.Visitor.html");
}
class FormFieldVisitor : public DocumentVisitor
{
public:
FormFieldVisitor()
{
mBuilder = MakeObject<System::Text::StringBuilder>();
}
VisitorAction VisitFormField(SharedPtr<FormField> formField) override
{
AppendLine(System::ObjectExt::ToString(formField->get_Type()) + u": \"" + formField->get_Name() + u"\"");
AppendLine(String(u"\tStatus: ") + (formField->get_Enabled() ? String(u"Enabled") : String(u"Disabled")));
AppendLine(String(u"\tHelp Text: ") + formField->get_HelpText());
AppendLine(String(u"\tEntry macro name: ") + formField->get_EntryMacro());
AppendLine(String(u"\tExit macro name: ") + formField->get_ExitMacro());
switch (formField->get_Type())
{
AppendLine(String(u"\tDrop-down items count: ") + formField->get_DropDownItems()->get_Count() + u", default selected item index: " +
formField->get_DropDownSelectedIndex());
AppendLine(String(u"\tDrop-down items: ") + String::Join(u", ", formField->get_DropDownItems()->LINQ_ToArray()));
break;
AppendLine(String(u"\tCheckbox size: ") + formField->get_CheckBoxSize());
AppendLine(String(u"\t") + u"Checkbox is currently: " + (formField->get_Checked() ? String(u"checked, ") : String(u"unchecked, ")) +
u"by default: " + (formField->get_Default() ? String(u"checked") : String(u"unchecked")));
break;
AppendLine(String(u"\tInput format: ") + formField->get_TextInputFormat());
AppendLine(String(u"\tCurrent contents: ") + formField->get_Result());
break;
default:
break;
}
// Let the visitor continue visiting other nodes.
}
String GetText()
{
return mBuilder->ToString();
}
private:
SharedPtr<System::Text::StringBuilder> mBuilder;
void AppendLine(String text)
{
mBuilder->Append(text + u'\n');
}
};

◆ get_Type()

Aspose::Words::Fields::FieldType Aspose::Words::Fields::FormField::get_Type ( )

Returns the form field type.

Examples

Shows how to insert a combo box.

auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
builder->Write(u"Please select a fruit: ");
// Insert a combo box which will allow a user to choose an option from a collection of strings.
SharedPtr<FormField> comboBox = builder->InsertComboBox(u"MyComboBox", MakeArray<String>({u"Apple", u"Banana", u"Cherry"}), 0);
ASSERT_EQ(u"MyComboBox", comboBox->get_Name());
ASSERT_EQ(FieldType::FieldFormDropDown, comboBox->get_Type());
ASSERT_EQ(u"Apple", comboBox->get_Result());
// The form field will appear in the form of a "select" html tag.
doc->Save(ArtifactsDir + u"FormFields.Create.html");

◆ GetType()

virtual const System::TypeInfo& Aspose::Words::Fields::FormField::GetType ( ) const
overridevirtual

Reimplemented from Aspose::Words::SpecialChar.

◆ Is()

virtual bool Aspose::Words::Fields::FormField::Is ( const System::TypeInfo target) const
overridevirtual

Reimplemented from Aspose::Words::SpecialChar.

◆ RemoveField()

void Aspose::Words::Fields::FormField::RemoveField ( )

Removes the complete form field, not just the form field special character.

Examples

Shows how to delete a form field.

auto doc = MakeObject<Document>(MyDir + u"Form fields.docx");
SharedPtr<FormField> formField = doc->get_Range()->get_FormFields()->idx_get(3);
formField->RemoveField();

◆ set_CalculateOnExit()

void Aspose::Words::Fields::FormField::set_CalculateOnExit ( bool  value)

◆ set_CheckBoxSize()

void Aspose::Words::Fields::FormField::set_CheckBoxSize ( double  value)

◆ set_Checked()

void Aspose::Words::Fields::FormField::set_Checked ( bool  value)

◆ set_Default()

void Aspose::Words::Fields::FormField::set_Default ( bool  value)

◆ set_DropDownSelectedIndex()

void Aspose::Words::Fields::FormField::set_DropDownSelectedIndex ( int32_t  value)

◆ set_Enabled()

void Aspose::Words::Fields::FormField::set_Enabled ( bool  value)

◆ set_EntryMacro()

void Aspose::Words::Fields::FormField::set_EntryMacro ( const System::String value)

◆ set_ExitMacro()

void Aspose::Words::Fields::FormField::set_ExitMacro ( const System::String value)

◆ set_HelpText()

void Aspose::Words::Fields::FormField::set_HelpText ( const System::String value)

◆ set_IsCheckBoxExactSize()

void Aspose::Words::Fields::FormField::set_IsCheckBoxExactSize ( bool  value)

◆ set_MaxLength()

void Aspose::Words::Fields::FormField::set_MaxLength ( int32_t  value)

◆ set_Name()

void Aspose::Words::Fields::FormField::set_Name ( const System::String value)

◆ set_OwnHelp()

void Aspose::Words::Fields::FormField::set_OwnHelp ( bool  value)

◆ set_OwnStatus()

void Aspose::Words::Fields::FormField::set_OwnStatus ( bool  value)

◆ set_Result()

void Aspose::Words::Fields::FormField::set_Result ( const System::String value)

◆ set_StatusText()

void Aspose::Words::Fields::FormField::set_StatusText ( const System::String value)

◆ set_TextInputDefault()

void Aspose::Words::Fields::FormField::set_TextInputDefault ( const System::String value)

◆ set_TextInputFormat()

void Aspose::Words::Fields::FormField::set_TextInputFormat ( const System::String value)

◆ set_TextInputType()

void Aspose::Words::Fields::FormField::set_TextInputType ( Aspose::Words::Fields::TextFormFieldType  value)

◆ SetTextInputValue()

void Aspose::Words::Fields::FormField::SetTextInputValue ( const System::SharedPtr< System::Object > &  newValue)

Applies the text format specified in TextInputFormat and stores the value in Result.

Parameters
newValueCan be a string, number or a DateTime object.
Examples

Shows how insert different kinds of form fields into a document, and process them with using a document visitor implementation.

void Visitor()
{
auto doc = MakeObject<Document>();
auto builder = MakeObject<DocumentBuilder>(doc);
// Use a document builder to insert a combo box.
builder->Write(u"Choose a value from this combo box: ");
SharedPtr<FormField> comboBox = builder->InsertComboBox(u"MyComboBox", MakeArray<String>({u"One", u"Two", u"Three"}), 0);
comboBox->set_CalculateOnExit(true);
ASSERT_EQ(3, comboBox->get_DropDownItems()->get_Count());
ASSERT_EQ(0, comboBox->get_DropDownSelectedIndex());
ASSERT_TRUE(comboBox->get_Enabled());
builder->InsertBreak(BreakType::ParagraphBreak);
// Use a document builder to insert a check box.
builder->Write(u"Click this check box to tick/untick it: ");
SharedPtr<FormField> checkBox = builder->InsertCheckBox(u"MyCheckBox", false, 50);
checkBox->set_IsCheckBoxExactSize(true);
checkBox->set_HelpText(u"Right click to check this box");
checkBox->set_OwnHelp(true);
checkBox->set_StatusText(u"Checkbox status text");
checkBox->set_OwnStatus(true);
ASPOSE_ASSERT_EQ(50.0, checkBox->get_CheckBoxSize());
ASSERT_FALSE(checkBox->get_Checked());
ASSERT_FALSE(checkBox->get_Default());
builder->InsertBreak(BreakType::ParagraphBreak);
// Use a document builder to insert text input form field.
builder->Write(u"Enter text here: ");
SharedPtr<FormField> textInput = builder->InsertTextInput(u"MyTextInput", TextFormFieldType::Regular, u"", u"Placeholder text", 50);
textInput->set_EntryMacro(u"EntryMacro");
textInput->set_ExitMacro(u"ExitMacro");
textInput->set_TextInputDefault(u"Regular");
textInput->set_TextInputFormat(u"FIRST CAPITAL");
textInput->SetTextInputValue(System::ObjectExt::Box<String>(u"New placeholder text"));
ASSERT_EQ(TextFormFieldType::Regular, textInput->get_TextInputType());
ASSERT_EQ(50, textInput->get_MaxLength());
// This collection contains all our form fields.
SharedPtr<FormFieldCollection> formFields = doc->get_Range()->get_FormFields();
ASSERT_EQ(3, formFields->get_Count());
// Fields display our form fields. We can see their field codes by opening this document
// in Microsoft and pressing Alt + F9. These fields have no switches,
// and members of the FormField object fully govern their form fields' content.
ASSERT_EQ(3, doc->get_Range()->get_Fields()->get_Count());
ASSERT_EQ(u" FORMDROPDOWN \u0001", doc->get_Range()->get_Fields()->idx_get(0)->GetFieldCode());
ASSERT_EQ(u" FORMCHECKBOX \u0001", doc->get_Range()->get_Fields()->idx_get(1)->GetFieldCode());
ASSERT_EQ(u" FORMTEXT \u0001", doc->get_Range()->get_Fields()->idx_get(2)->GetFieldCode());
// Allow each form field to accept a document visitor.
auto formFieldVisitor = MakeObject<ExFormFields::FormFieldVisitor>();
{
SharedPtr<System::Collections::Generic::IEnumerator<SharedPtr<FormField>>> fieldEnumerator = formFields->GetEnumerator();
while (fieldEnumerator->MoveNext())
{
fieldEnumerator->get_Current()->Accept(formFieldVisitor);
}
}
std::cout << formFieldVisitor->GetText() << std::endl;
doc->UpdateFields();
doc->Save(ArtifactsDir + u"FormFields.Visitor.html");
}
class FormFieldVisitor : public DocumentVisitor
{
public:
FormFieldVisitor()
{
mBuilder = MakeObject<System::Text::StringBuilder>();
}
VisitorAction VisitFormField(SharedPtr<FormField> formField) override
{
AppendLine(System::ObjectExt::ToString(formField->get_Type()) + u": \"" + formField->get_Name() + u"\"");
AppendLine(String(u"\tStatus: ") + (formField->get_Enabled() ? String(u"Enabled") : String(u"Disabled")));
AppendLine(String(u"\tHelp Text: ") + formField->get_HelpText());
AppendLine(String(u"\tEntry macro name: ") + formField->get_EntryMacro());
AppendLine(String(u"\tExit macro name: ") + formField->get_ExitMacro());
switch (formField->get_Type())
{
AppendLine(String(u"\tDrop-down items count: ") + formField->get_DropDownItems()->get_Count() + u", default selected item index: " +
formField->get_DropDownSelectedIndex());
AppendLine(String(u"\tDrop-down items: ") + String::Join(u", ", formField->get_DropDownItems()->LINQ_ToArray()));
break;
AppendLine(String(u"\tCheckbox size: ") + formField->get_CheckBoxSize());
AppendLine(String(u"\t") + u"Checkbox is currently: " + (formField->get_Checked() ? String(u"checked, ") : String(u"unchecked, ")) +
u"by default: " + (formField->get_Default() ? String(u"checked") : String(u"unchecked")));
break;
AppendLine(String(u"\tInput format: ") + formField->get_TextInputFormat());
AppendLine(String(u"\tCurrent contents: ") + formField->get_Result());
break;
default:
break;
}
// Let the visitor continue visiting other nodes.
}
String GetText()
{
return mBuilder->ToString();
}
private:
SharedPtr<System::Text::StringBuilder> mBuilder;
void AppendLine(String text)
{
mBuilder->Append(text + u'\n');
}
};

◆ Type()

static const System::TypeInfo& Aspose::Words::Fields::FormField::Type ( )
static