# Javascript: FormFieldCollection.addTextFormField Method

> Adds a new TextFormField.

- **Product:** TX Text Control .NET Server
- **Section:** Reference
- **Kind:** Method
- **Introduced:** 28.0
- **Path:** TX Text Control .NET Server > Reference > JavaScript API > Javascript: FormFieldCollection.addTextFormField Method
- **467 words**
- **Web URL:** https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/javascript/formfieldcollection/addtextformfield-method/
- **LLMs URL:** https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/javascript/formfieldcollection/addtextformfield-method/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/javascript/formfieldcollection/addtextformfield-method/llms-full.txt

---

### Description

Adds a new [TextFormField](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/javascript/textformfield/llms-full.txt).

### Syntax

```javascript
<void> FormFieldCollection.addTextFormField(<Number> emptyWidth, [<RequestTextFormFieldCallback> callback], [<ErrorCallback> errorCallback])
```

### Parameters

| Parameter | Description |
|---|---|
| emptyWidth | Specifies the horizontal extension, in twips, of the TextFormField, when there is no text. When this parameter is set to 0, a default value is used. |
| callback | Optional. Receives the added TextFormField. |
| errorCallback | Optional. Is called when the operation failed with an error. |

### Examples

The following example demonstrates `FormFieldCollection.addTextFormField` in a practical document-editing workflow. It adds a new TextFormField.

```javascript
function onTxError(error) {
    console.error("TX Text Control error:", error.msg);
    error.handled = true;
}

TXTextControl.textParts.getMainText(function(mainText) {
    const formFields = mainText.formFields;
    formFields.addTextFormField(
        1440,
        function(textFormField) {
            if (!textFormField) {
                console.warn("No text form field was returned.");
                return;
            }
            
            console.log("add text form field result:", textFormField);
        },
        onTxError
    );
}, onTxError);
```

---

## Nearby

- **Previous:** [Javascript: FormFieldCollection.addSelectionFormField Method](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/javascript/formfieldcollection/addselectionformfield-method/llms-full.txt)
- **Next:** [Javascript: FormFieldCollection.getItem Method](https://docs.textcontrol.com/tx-text-control-dotnet-server/reference/javascript/formfieldcollection/getitem-method/llms-full.txt)
