# Class FormElement

- [TopLevel.Object](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md)
  - [dw.web.FormElement](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.web.FormElement.md)

Represents a form element.

## All Known Subclasses

[Form](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.web.Form.md), [FormAction](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.web.FormAction.md), [FormField](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.web.FormField.md), [FormGroup](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.web.FormGroup.md), [FormList](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.web.FormList.md), [FormListItem](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.web.FormListItem.md)

## Property Summary

| Property                                                                                                                                                                        | Description                                                                               |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------- |
| [dynamicHtmlName](#dynamichtmlname): [String](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.String.md) `(read-only)`                                           | Returns a dynamic html name for the field.                                                |
| [formId](#formid): [String](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.String.md) `(read-only)`                                                             | The ID of the form element.                                                               |
| [htmlName](#htmlname): [String](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.String.md) `(read-only)`                                                         | Returns the global unique name of the field, which can be used as name  in the html form. |
| [parent](#parent): [FormElement](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.web.FormElement.md) `(read-only)`                                                     | The parent within the form.                                                               |
| [valid](#valid): [Boolean](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Boolean.md) `(read-only)`                                                             | Identifies if this element and all its children elements are  valid.                      |
| [validationResult](#validationresult): [FormElementValidationResult](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.web.FormElementValidationResult.md) `(read-only)` | Provides a combined view on the validation status as per isValid() and getError().        |

## Constructor Summary

This class does not have a constructor, so you cannot create it directly.

## Method Summary

| Method                                                                                                                                                                                                               | Description                                                                               |
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------- |
| [clearFormElement](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.web.FormElement.md#clearformelement)()                                                                                                   | This method clears the whole form.                                                        |
| [getDynamicHtmlName](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.web.FormElement.md#getdynamichtmlname)()                                                                                               | Returns a dynamic html name for the field.                                                |
| [getFormId](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.web.FormElement.md#getformid)()                                                                                                                 | The ID of the form element.                                                               |
| [getHtmlName](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.web.FormElement.md#gethtmlname)()                                                                                                             | Returns the global unique name of the field, which can be used as name  in the html form. |
| [getParent](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.web.FormElement.md#getparent)()                                                                                                                 | The parent within the form.                                                               |
| [getValidationResult](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.web.FormElement.md#getvalidationresult)()                                                                                             | Provides a combined view on the validation status as per isValid() and getError().        |
| [invalidateFormElement](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.web.FormElement.md#invalidateformelement)()                                                                                         | The method can be called to explicitly invalidate a form element.                         |
| [invalidateFormElement](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.web.FormElement.md#invalidateformelementstring)([String](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.String.md)) | The method can be called to explicitly invalidate a field.                                |
| [isValid](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.web.FormElement.md#isvalid)()                                                                                                                     | Identifies if this element and all its children elements are  valid.                      |

### Methods inherited from class Object

[assign](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#assignobject-object), [create](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#createobject), [create](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#createobject-object), [defineProperties](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#definepropertiesobject-object), [defineProperty](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#definepropertyobject-object-object), [entries](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#entriesobject), [freeze](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#freezeobject), [fromEntries](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#fromentriesiterable), [getOwnPropertyDescriptor](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#getownpropertydescriptorobject-object), [getOwnPropertyNames](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#getownpropertynamesobject), [getOwnPropertySymbols](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#getownpropertysymbolsobject), [getPrototypeOf](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#getprototypeofobject), [hasOwnProperty](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#hasownpropertystring), [is](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#isobject-object), [isExtensible](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#isextensibleobject), [isFrozen](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#isfrozenobject), [isPrototypeOf](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#isprototypeofobject), [isSealed](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#issealedobject), [keys](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#keysobject), [preventExtensions](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#preventextensionsobject), [propertyIsEnumerable](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#propertyisenumerablestring), [seal](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#sealobject), [setPrototypeOf](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#setprototypeofobject-object), [toLocaleString](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#tolocalestring), [toString](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#tostring), [valueOf](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#valueof), [values](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md#valuesobject)

## Property Details

### dynamicHtmlName

- dynamicHtmlName: [String](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.String.md) `(read-only)`
  - : Returns a dynamic html name for the field. It can be used to suppress any autocompletion
    support from a browser, e.g. for credit card related fields. It can be also
    used for a unique form name, if one form is used multiple times in a page.

***

### formId

- formId: [String](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.String.md) `(read-only)`
  - : The ID of the form element. The is is unique within the parent
    element of the form.

***

### htmlName

- htmlName: [String](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.String.md) `(read-only)`
  - : Returns the global unique name of the field, which can be used as name
    in the html form. For radio buttons this name is not unique.

***

### parent

- parent: [FormElement](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.web.FormElement.md) `(read-only)`
  - : The parent within the form.

***

### valid

- valid: [Boolean](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Boolean.md) `(read-only)`
  - : Identifies if this element and all its children elements are
    valid. A form element, which was not submitted in the last
    request is always valid.

***

### validationResult

- validationResult: [FormElementValidationResult](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.web.FormElementValidationResult.md) `(read-only)`
  - : Provides a combined view on the validation status as per isValid() and getError(). In
    addition it also provides the data as returned by the validation in case a validation
    script was used.

***

## Method Details

### clearFormElement()

- clearFormElement(): void
  - : This method clears the whole form. After clearing a form it
    contains no value or the default value, is not bound to any business
    object and has the status of being valid.

***

### getDynamicHtmlName()

- getDynamicHtmlName(): [String](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.String.md)
  - : Returns a dynamic html name for the field. It can be used to suppress any autocompletion
    support from a browser, e.g. for credit card related fields. It can be also
    used for a unique form name, if one form is used multiple times in a page.

    **Returns:**

    - a dynamic html name.

***

### getFormId()

- getFormId(): [String](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.String.md)
  - : The ID of the form element. The is is unique within the parent
    element of the form.

    **Returns:**

    - the ID of the form.

***

### getHtmlName()

- getHtmlName(): [String](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.String.md)
  - : Returns the global unique name of the field, which can be used as name
    in the html form. For radio buttons this name is not unique.

    **Returns:**

    - the global unique name of the field.

***

### getParent()

- getParent(): [FormElement](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.web.FormElement.md)
  - : The parent within the form.

    **Returns:**

    - the parent within the form.

***

### getValidationResult()

- getValidationResult(): [FormElementValidationResult](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.web.FormElementValidationResult.md)
  - : Provides a combined view on the validation status as per isValid() and getError(). In
    addition it also provides the data as returned by the validation in case a validation
    script was used.

    **Returns:**

    - the validation status (valid, error, data)

***

### invalidateFormElement()

- invalidateFormElement(): void
  - : The method can be called to explicitly invalidate a form element. The
    error text will be set to the one of two possible preconfigured custom
    error messages associated with the form definition. The "value-error"
    message will be used for FormField instances and "form-error" will be
    used for FormGroup instances.

***

### invalidateFormElement(String)

- invalidateFormElement(error: [String](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.String.md)): void
  - : The method can be called to explicitly invalidate a field. The error
    text is set to the given error message.

    **Parameters:**

    - error - the error text to use.

***

### isValid()

- isValid(): [Boolean](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Boolean.md)
  - : Identifies if this element and all its children elements are
    valid. A form element, which was not submitted in the last
    request is always valid.

    **Returns:**

    - true if this element and all its children elements are valid,
      false otherwise.

***
