@ngdoc overview
@name Developer Guide: Forms
@description
# Overview
Forms allow users to enter data into your application. Forms represent the bidirectional data
bindings in Angular.
Forms consist of all of the following:
  - the individual widgets with which users interact
  - the validation rules for widgets
  - the form, a collection of widgets that contains aggregated validation information
# Form
A form groups a set of widgets together into a single logical data-set. A form is created using
the {@link api/angular.widget.form <form>} element that calls the
{@link api/angular.module.ng.$formFactory $formFactory} service. The form is responsible for managing
the widgets and for tracking validation information.
A form is:
- The collection which contains widgets or other forms.
- Responsible for marshaling data from the model into a widget. This is
  triggered by {@link api/angular.module.ng.$rootScope.Scope#$watch $watch} of the model expression.
- Responsible for marshaling data from the widget into the model. This is
  triggered by the widget emitting the `$viewChange` event.
- Responsible for updating the validation state of the widget, when the widget emits
  `$valid` / `$invalid` event. The validation state is useful for controlling the validation
   errors shown to the user in it consist of:
  - `$valid` / `$invalid`: Complementary set of booleans which show if a widget is valid / invalid.
  - `$error`: an object which has a property for each validation key emited by the widget.
              The value of the key is always true. If widget is valid, then the `$error`
              object has no properties. For example if the widget emits
              `$invalid` event with `REQUIRED` key. The internal state of the `$error` would be
              updated to `$error.REQUIRED == true`.
- Responsible for aggregating widget validation information into the form.
  - `$valid` / `$invalid`: Complementary set of booleans which show if all the child widgets
              (or forms) are valid or if any are invalid.
  - `$error`: an object which has a property for each validation key emited by the
              child widget. The value of the key is an array of widgets which fired the invalid
              event. If all child widgets are valid then, then the `$error` object has no
              properties. For example if a child widget emits
              `$invalid` event with `REQUIRED` key. The internal state of the `$error` would be
              updated to `$error.REQUIRED == [ widgetWhichEmitedInvalid ]`.
# Widgets
In Angular, a widget is the term used for the UI with which the user input. Examples of
bult-in Angular widgets are {@link api/angular.widget.input input} and
{@link api/angular.widget.select select}. Widgets provide the rendering and the user
interaction logic. Widgets should be declared inside a form, if no form is provided an implicit
form {@link api/angular.module.ng.$formFactory $formFactory.rootForm} form is used.
Widgets are implemented as Angular controllers. A widget controller:
-  implements methods:
  - `$render` - Updates the DOM from the internal state as represented by `$viewValue`.
  - `$parseView` - Translate `$viewValue` to `$modelValue`. (`$modelValue` will be assigned to
     the model scope by the form)
  - `$parseModel` - Translate `$modelValue` to `$viewValue`. (`$viewValue` will be assigned to
     the DOM inside the `$render` method)
- responds to events:
  - `$validate` - Emitted by the form when the form determines that the widget needs to validate
    itself. There may be more then one listener on the `$validate` event. The widget responds
    by emitting `$valid` / `$invalid` event of its own.
- emits events:
  - `$viewChange` - Emitted when the user interacts with the widget and it is necessary to update
     the model.
  - `$valid` - Emitted when the widget determines that it is valid (usually as a response to
    `$validate` event or inside `$parseView()` or `$parseModel()` method).
  - `$invalid` - Emitted when the widget determines that it is invalid (usually as a response to
    `$validate` event or inside `$parseView()` or `$parseModel()` method).
  - `$destroy` - Emitted when the widget element is removed from the DOM.
# CSS
Angular-defined widgets and forms set `ng-valid` and `ng-invalid` classes on themselves to allow
the web-designer a way to style them. If you write your own widgets, then their `$render()`
methods must set the appropriate CSS classes to allow styling.
(See {@link dev_guide.templates.css-styling CSS})
# Example
The following example demonstrates:
  - How an error is displayed when a required field is empty.
  - Error highlighting.
  - How form submission is disabled when the form is invalid.
  - The internal state of the widget and form in the the 'Debug View' area.
     Debug View:
     form={{form|json}}
     master={{master}|json}
     userForm={{userForm|json}}
     addressForm={{addressForm|json}}