ApiComboBoxForm

new ApiComboBoxForm()

Class representing a document combo box / dropdown list.

Properties

Name Type Description
editable boolean

Specifies if the combo box text can be edited.

autoFit boolean

Specifies if the combo box form content should be autofit, i.e. whether the font size adjusts to the size of the fixed size form.

items Array.<(string|Array.)>

The combo box items. This array consists of strings or arrays of two strings where the first string is the displayed value and the second one is its meaning. If the array consists of single strings, then the displayed value and its meaning are the same. Example: ["First", ["Second", "2"], ["Third", "3"], "Fourth"].

Methods

Name Description
Clear

Clears the current form.

Copy

Copies the current form (copies with the shape if it exists).

GetClassType

Returns a type of the ApiFormBase class.

GetFormKey

Returns the current form key.

GetFormType

Returns a type of the current form.

GetListValues

Returns the list values from the current combo box.

GetText

Returns the text from the current form. This method is used only for text and combo box forms.

GetTextPr

Returns the text properties from the current form. This method is used only for text and combo box forms.

GetTipText

Returns the tip text of the current form.

GetWrapperShape

Returns a shape in which the form is placed to control the position and size of the fixed size form frame. The null value will be returned for the inline forms.

IsEditable

Checks if the combo box text can be edited. If it is not editable, then this form is a dropdown list.

IsFixed

Checks if the current form is fixed size.

IsRequired

Checks if the current form is required.

SelectListValue

Selects the specified value from the combo box list values.

SetBackgroundColor

Sets the background color to the current form.

SetBorderColor

Sets the border color to the current form.

SetFormKey

Sets a key to the current form.

SetListValues

Sets the list values to the current combo box.

SetPlaceholderText

Sets the placeholder text to the current form. Can't be set to checkbox or radio button.

SetRequired

Specifies if the current form should be required.

SetText

Sets the text to the current combo box. Available only for editable combo box forms.

SetTextPr

Sets the text properties to the current form. This method is used only for text and combo box forms.

SetTipText

Sets the tip text to the current form.

ToFixed

Converts the current form to a fixed size form.

ToInline

Converts the current form to an inline form. Picture form can't be converted to an inline form, it's always a fixed size object.

Example

Copy code
builder.CreateFile("docx");
var oDocument = Api.GetDocument();
var oComboBoxForm = Api.CreateComboBoxForm({"key": "Personal information", "tip": "Choose your country", "required": true, "placeholder": "Country", "editable": true, "autoFit": false});
var oParagraph = oDocument.GetElement(0);
oParagraph.AddElement(oComboBoxForm);
oComboBoxForm.SetListValues(["Latvia", "USA", "UK"]);
oComboBoxForm.SetText("France");
oComboBoxForm.SelectListValue("USA");
var aListValues = oComboBoxForm.GetListValues();
oParagraph = Api.CreateParagraph();
oParagraph.AddText("Combo box list values: ");
oParagraph.AddLineBreak();
for (let i = 0; i < aListValues.length; i++ ){
    oParagraph.AddText(aListValues[i]);
    oParagraph.AddLineBreak();
}
var bEdit = oComboBoxForm.IsEditable();
oParagraph.AddLineBreak();
oParagraph.AddText("The first combo box from this document is editable: " + bEdit);
oDocument.Push(oParagraph);
builder.SaveFile("docx", "ApiComboBoxForm.docx");
builder.CloseFile();

Resulting document