# Class FormGroup

- [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)
    - [dw.web.FormGroup](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.web.FormGroup.md)

The class is the central class within the whole form handling. It is
the container element for fields and other form elements. A form group
can contain other forms, also called sub-forms.

Access to the elements of a form is provided via an index based access or
via an associative array access. For example, the field "firstname" can be accessed
with the expression "myform.firstname".

## All Known Subclasses

[Form](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.web.Form.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                                                  |
| ------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------ |
| [childCount](#childcount): [Number](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Number.md) `(read-only)`                 | Returns the number of elements in the form.                  |
| [error](#error): [String](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.String.md) `(read-only)`                           | Returns a form-wide error message.                           |
| [object](#object): [Object](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md) `(read-only)`                         | The object that was bound to this form group.                |
| [submittedAction](#submittedaction): [FormAction](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.web.FormAction.md) `(read-only)` | Returns the action that was submitted with the last request. |
| [triggeredAction](#triggeredaction): [FormAction](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.web.FormAction.md) `(read-only)` | Returns the action that was triggered with the last request. |

## Constructor Summary

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

## Method Summary

| Method                                                                                                                                                                                   | Description                                                                                                                                                                                                                       |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [accept](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.web.FormGroup.md#accept)()                                                                                             | The method copies the value from a form into the object, which was previously  bound to the form.                                                                                                                                 |
| [copyFrom](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.web.FormGroup.md#copyfromobject)([Object](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md)) | The method updates the form with the values from the given object.    The method call is basically equivalent to the pipelet UpdateFormWithObject.    The method not only copies the value, it also binds the object to the form. |
| [copyTo](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.web.FormGroup.md#copytoobject)([Object](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md))     | The method updates the object with the values from the form.    The method call is basically equivalent to the pipelet UpdateObjectWithForm.    The method needs a submitted form.                                                |
| [getChildCount](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.web.FormGroup.md#getchildcount)()                                                                               | Returns the number of elements in the form.                                                                                                                                                                                       |
| [getError](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.web.FormGroup.md#geterror)()                                                                                         | Returns a form-wide error message.                                                                                                                                                                                                |
| [getObject](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.web.FormGroup.md#getobject)()                                                                                       | The object that was bound to this form group.                                                                                                                                                                                     |
| [getSubmittedAction](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.web.FormGroup.md#getsubmittedaction)()                                                                     | Returns the action that was submitted with the last request.                                                                                                                                                                      |
| [getTriggeredAction](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.web.FormGroup.md#gettriggeredaction)()                                                                     | Returns the action that was triggered with the last request.                                                                                                                                                                      |

### Methods inherited from class FormElement

[clearFormElement](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.web.FormElement.md#clearformelement), [getDynamicHtmlName](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.web.FormElement.md#getdynamichtmlname), [getFormId](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.web.FormElement.md#getformid), [getHtmlName](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.web.FormElement.md#gethtmlname), [getParent](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.web.FormElement.md#getparent), [getValidationResult](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.web.FormElement.md#getvalidationresult), [invalidateFormElement](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.web.FormElement.md#invalidateformelement), [invalidateFormElement](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.web.FormElement.md#invalidateformelementstring), [isValid](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.web.FormElement.md#isvalid)

### 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

### childCount

- childCount: [Number](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Number.md) `(read-only)`
  - : Returns the number of elements in the form.

***

### error

- error: [String](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.String.md) `(read-only)`
  - : Returns a form-wide error message. If no error message
    is present the method returns null.

***

### object

- object: [Object](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md) `(read-only)`
  - : The object that was bound to this form group.

***

### submittedAction

- submittedAction: [FormAction](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.web.FormAction.md) `(read-only)`
  - : Returns the action that was submitted with the last request. The action is
    set independent whether the form must be valid for this action. The method
    returns null if no action at all was submitted with the last request for this
    form group.

***

### triggeredAction

- triggeredAction: [FormAction](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.web.FormAction.md) `(read-only)`
  - : Returns the action that was triggered with the last request. An action is
    only marked as triggered if the constraints regarding form validation are
    meet. The method returns null if no action was marked as triggered.

***

## Method Details

### accept()

- accept(): void
  - : The method copies the value from a form into the object, which was previously
    bound to the form. The method is equivalent to the pipelet AcceptForm.

    This method is equivalent to the call formgroup.copyFrom( formgroup.object ).

***

### copyFrom(Object)

- copyFrom(obj: [Object](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md)): void
  - : The method updates the form with the values from the given object.

    The method call is basically equivalent to the pipelet UpdateFormWithObject.

    The method not only copies the value, it also binds the object to the form. Binding means that the form keeps the
    information from which objects the values were taken. This can be used for two purposes:

    1. for lists it makes it easier in the code to find the associated object, for example in case of a related   action, and
    2. it allows to copy back the values from the form into the object (see [accept()](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.web.FormGroup.md#accept)).

    Because of this bind behavior, the operation is also sometimes called a bind-operation.

    **Parameters:**

    - obj - the object from, which the values are read

***

### copyTo(Object)

- copyTo(obj: [Object](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md)): void
  - : The method updates the object with the values from the form.

    The method call is basically equivalent to the pipelet UpdateObjectWithForm.

    The method needs a submitted form. The copyTo call is delegated to the form fields. Each form field than checks
    if its value was submitted as part of the form:

    - If this is *true*, the object gets updated with the form field value.
    - If this is *false*, the object will not be updated.

    This is the reason why you cannot copy values from one object into another object by using
    [copyFrom(Object)](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.web.FormGroup.md#copyfromobject) and [copyTo(Object)](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.web.FormGroup.md#copytoobject) within the same request (e.g. by one call to a script or
    controller).

    **Parameters:**

    - obj - the object, which is updated from the form

***

### getChildCount()

- getChildCount(): [Number](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Number.md)
  - : Returns the number of elements in the form.

    **Returns:**

    - the number of elements in the form.

***

### getError()

- getError(): [String](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.String.md)
  - : Returns a form-wide error message. If no error message
    is present the method returns null.

    **Returns:**

    - a form-wide error message or null.

***

### getObject()

- getObject(): [Object](/docs/commerce/b2c-commerce/references/b2c-script-api/TopLevel.Object.md)
  - : The object that was bound to this form group.

    **Returns:**

    - the bound object.

***

### getSubmittedAction()

- getSubmittedAction(): [FormAction](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.web.FormAction.md)
  - : Returns the action that was submitted with the last request. The action is
    set independent whether the form must be valid for this action. The method
    returns null if no action at all was submitted with the last request for this
    form group.

    **Returns:**

    - the action that was submitted with the last request or null.

***

### getTriggeredAction()

- getTriggeredAction(): [FormAction](/docs/commerce/b2c-commerce/references/b2c-script-api/dw.web.FormAction.md)
  - : Returns the action that was triggered with the last request. An action is
    only marked as triggered if the constraints regarding form validation are
    meet. The method returns null if no action was marked as triggered.

    **Returns:**

    - the action that was triggered with the last request.

***
