# Javascript: FormFieldCollection.addDateFormField Method

> Adds a new DateFormField.

- **Product:** DS Server
- **Section:** Reference
- **Kind:** Method
- **Introduced:** 28.0
- **Path:** DS Server > Reference > JavaScript API > Javascript: FormFieldCollection.addDateFormField Method
- **464 words**
- **Web URL:** https://docs.textcontrol.com/ds-server/reference/javascript/formfieldcollection/adddateformfield-method/
- **LLMs URL:** https://docs.textcontrol.com/ds-server/reference/javascript/formfieldcollection/adddateformfield-method/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/ds-server/reference/javascript/formfieldcollection/adddateformfield-method/llms-full.txt

---

### Description

Adds a new [DateFormField](https://docs.textcontrol.com/ds-server/reference/javascript/dateformfield/llms-full.txt).

### Syntax

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

### Parameters

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

### Examples

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

```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.addDateFormField(
        1440,
        function(dateFormField) {
            if (!dateFormField) {
                console.warn("No date form field was returned.");
                return;
            }
            
            console.log("add date form field result:", dateFormField);
        },
        onTxError
    );
}, onTxError);
```

---

## Nearby

- **Previous:** [Javascript: FormFieldCollection.addCheckFormField Method](https://docs.textcontrol.com/ds-server/reference/javascript/formfieldcollection/addcheckformfield-method/llms-full.txt)
- **Next:** [Javascript: FormFieldCollection.addSelectionFormField Method](https://docs.textcontrol.com/ds-server/reference/javascript/formfieldcollection/addselectionformfield-method/llms-full.txt)
