Skip to content

Commit

Permalink
Updated types articles
Browse files Browse the repository at this point in the history
  • Loading branch information
wouterj committed May 23, 2015
1 parent 03fdc5b commit 55246be
Show file tree
Hide file tree
Showing 30 changed files with 261 additions and 223 deletions.
10 changes: 6 additions & 4 deletions reference/forms/types/birthday.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ birthday Field Type
A :doc:`date </reference/forms/types/date>` field that specializes in handling
birthdate data.

Can be rendered as a single text box, three text boxes (month, day, and year),
Can be rendered as a single text box, three text boxes (month, day and year),
or three select boxes.

This type is essentially the same as the :doc:`date </reference/forms/types/date>`
Expand All @@ -22,7 +22,7 @@ option defaults to 120 years ago to the current year.
+----------------------+-------------------------------------------------------------------------------+
| Overridden options | - `years`_ |
+----------------------+-------------------------------------------------------------------------------+
| Inherited options | from the :doc:`date </reference/forms/types/date>` type: |
| Inherited options | from the :doc:`date </reference/forms/types/date>` type: |
| | |
| | - `days`_ |
| | - `empty_value`_ |
Expand Down Expand Up @@ -62,7 +62,8 @@ relevant when the ``widget`` option is set to ``choice``.
Inherited Options
-----------------

These options inherit from the :doc:`date </reference/forms/types/date>` type:
These options inherit from the :doc:`date </reference/forms/types/date>`
type:

.. include:: /reference/forms/types/options/days.rst.inc

Expand All @@ -80,7 +81,8 @@ These options inherit from the :doc:`date </reference/forms/types/date>` type:

.. include:: /reference/forms/types/options/date_widget.rst.inc

These options inherit from the :doc:`form </reference/forms/types/form>` type:
These options inherit from the :doc:`form </reference/forms/types/form>`
type:

.. include:: /reference/forms/types/options/data.rst.inc

Expand Down
6 changes: 3 additions & 3 deletions reference/forms/types/button.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ Inherited Options

The following options are defined in the
:class:`Symfony\\Component\\Form\\Extension\\Core\\Type\\BaseType` class.
The ``BaseType`` class is the parent class for both the ``button`` type and
the :doc:`form type </reference/forms/types/form>`, but it is not part of
the form type tree (i.e. it can not be used as a form type on its own).
The ``BaseType`` class is the parent class for both the ``button`` type
and the :doc:`form type </reference/forms/types/form>`, but it is not part
of the form type tree (i.e. it can not be used as a form type on its own).

.. include:: /reference/forms/types/options/button_attr.rst.inc

Expand Down
3 changes: 2 additions & 1 deletion reference/forms/types/checkbox.rst
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ Overridden Options
Inherited Options
-----------------

These options inherit from the :doc:`form </reference/forms/types/form>` type:
These options inherit from the :doc:`form </reference/forms/types/form>`
type:

.. include:: /reference/forms/types/options/data.rst.inc

Expand Down
29 changes: 14 additions & 15 deletions reference/forms/types/choice.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ option.
Example Usage
-------------

The easiest way to use this field is to specify the choices directly via the
``choices`` option. The key of the array becomes the value that's actually
The easiest way to use this field is to specify the choices directly via
the ``choices`` option. The key of the array becomes the value that's actually
set on your underlying object (e.g. ``m``), while the value is what the
user sees on the form (e.g. ``Male``).

Expand All @@ -57,9 +57,7 @@ user sees on the form (e.g. ``Male``).
By setting ``multiple`` to true, you can allow the user to choose multiple
values. The widget will be rendered as a multiple ``select`` tag or a series
of checkboxes depending on the ``expanded`` option:

.. code-block:: php
of checkboxes depending on the ``expanded`` option::

$builder->add('availability', 'choice', array(
'choices' => array(
Expand All @@ -70,8 +68,8 @@ of checkboxes depending on the ``expanded`` option:
'multiple' => true,
));

You can also use the ``choice_list`` option, which takes an object that can
specify the choices for your widget.
You can also use the ``choice_list`` option, which takes an object that
can specify the choices for your widget.

.. _forms-reference-choice-tags:

Expand All @@ -95,11 +93,11 @@ is the item value and the array value is the item's label::

.. tip::

When the values to choose from are not integers or strings (but e.g. floats
or booleans), you should use the `choice_list`_ option instead. With this
option you are able to keep the original data format which is important
to ensure that the user input is validated properly and useless database
updates caused by a data type mismatch are avoided.
When the values to choose from are not integers or strings (but e.g.
floats or booleans), you should use the `choice_list`_ option instead.
With this option you are able to keep the original data format which
is important to ensure that the user input is validated properly and
useless database updates caused by a data type mismatch are avoided.

choice_list
~~~~~~~~~~~
Expand Down Expand Up @@ -164,7 +162,8 @@ the parent field (the form in most cases).
Inherited Options
-----------------

These options inherit from the :doc:`form </reference/forms/types/form>` type:
These options inherit from the :doc:`form </reference/forms/types/form>`
type:

.. include:: /reference/forms/types/options/by_reference.rst.inc

Expand Down Expand Up @@ -215,5 +214,5 @@ Field Variables

.. tip::

It's significantly faster to use the :ref:`form-twig-selectedchoice` test
instead when using Twig.
It's significantly faster to use the :ref:`form-twig-selectedchoice`
test instead when using Twig.
91 changes: 50 additions & 41 deletions reference/forms/types/collection.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
collection Field Type
=====================

This field type is used to render a "collection" of some field or form. In
the easiest sense, it could be an array of ``text`` fields that populate
This field type is used to render a "collection" of some field or form.
In the easiest sense, it could be an array of ``text`` fields that populate
an array ``emails`` field. In more complex examples, you can embed entire
forms, which is useful when creating forms that expose one-to-many relationships
(e.g. a product from where you can manage many related product photos).
forms, which is useful when creating forms that expose one-to-many
relationships (e.g. a product from where you can manage many related product
photos).

+-------------+-----------------------------------------------------------------------------+
| Rendered as | depends on the `type`_ option |
Expand Down Expand Up @@ -45,8 +46,8 @@ forms, which is useful when creating forms that expose one-to-many relationships
Basic Usage
-----------

This type is used when you want to manage a collection of similar items in
a form. For example, suppose you have an ``emails`` field that corresponds
This type is used when you want to manage a collection of similar items
in a form. For example, suppose you have an ``emails`` field that corresponds
to an array of email addresses. In the form, you want to expose each email
address as its own input text box::

Expand Down Expand Up @@ -104,8 +105,8 @@ A much more flexible method would look like this:
<?php endforeach ?>
</ul>

In both cases, no input fields would render unless your ``emails`` data array
already contained some emails.
In both cases, no input fields would render unless your ``emails`` data
array already contained some emails.

In this simple example, it's still impossible to add new addresses or remove
existing addresses. Adding new addresses is possible by using the `allow_add`_
Expand Down Expand Up @@ -141,7 +142,11 @@ will look like this:

.. code-block:: html

<input type="email" id="form_emails___name__" name="form[emails][__name__]" value="" />
<input type="email"
id="form_emails___name__"
name="form[emails][__name__]"
value=""
/>

By replacing ``__name__`` with some unique value (e.g. ``2``),
you can build and insert new HTML fields into your form.
Expand All @@ -160,7 +165,8 @@ you need is the JavaScript:
{# ... #}

{# store the prototype on the data-prototype attribute #}
<ul id="email-fields-list" data-prototype="{{ form_widget(form.emails.vars.prototype)|e }}">
<ul id="email-fields-list"
data-prototype="{{ form_widget(form.emails.vars.prototype)|e }}">
{% for emailField in form.emails %}
<li>
{{ form_errors(emailField) }}
Expand Down Expand Up @@ -203,10 +209,10 @@ you need is the JavaScript:

If you're rendering the entire collection at once, then the prototype
is automatically available on the ``data-prototype`` attribute of the
element (e.g. ``div`` or ``table``) that surrounds your collection. The
only difference is that the entire "form row" is rendered for you, meaning
you wouldn't have to wrap it in any container element as it was done
above.
element (e.g. ``div`` or ``table``) that surrounds your collection.
The only difference is that the entire "form row" is rendered for you,
meaning you wouldn't have to wrap it in any container element as it
was done above.

Field Options
-------------
Expand All @@ -222,8 +228,9 @@ items as well as the new item that was in the submitted data. See the above
example for more details.

The `prototype`_ option can be used to help render a prototype item that
can be used - with JavaScript - to create new form items dynamically on the
client side. For more information, see the above example and :ref:`cookbook-form-collections-new-prototype`.
can be used - with JavaScript - to create new form items dynamically on
the client side. For more information, see the above example and
:ref:`cookbook-form-collections-new-prototype`.

.. caution::

Expand All @@ -249,11 +256,11 @@ For more information, see :ref:`cookbook-form-collections-remove`.

Be careful when using this option when you're embedding a collection
of objects. In this case, if any embedded forms are removed, they *will*
correctly be missing from the final array of objects. However, depending on
your application logic, when one of those objects is removed, you may want
to delete it or at least remove its foreign key reference to the main object.
None of this is handled automatically. For more information, see
:ref:`cookbook-form-collections-remove`.
correctly be missing from the final array of objects. However, depending
on your application logic, when one of those objects is removed, you
may want to delete it or at least remove its foreign key reference to
the main object. None of this is handled automatically. For more
information, see :ref:`cookbook-form-collections-remove`.

options
~~~~~~~
Expand All @@ -262,8 +269,9 @@ options

This is the array that's passed to the form type specified in the `type`_
option. For example, if you used the :doc:`choice </reference/forms/types/choice>`
type as your `type`_ option (e.g. for a collection of drop-down menus), then
you'd need to at least pass the ``choices`` option to the underlying type::
type as your `type`_ option (e.g. for a collection of drop-down menus),
then you'd need to at least pass the ``choices`` option to the underlying
type::

$builder->add('favorite_cities', 'collection', array(
'type' => 'choice',
Expand All @@ -283,13 +291,13 @@ prototype
**type**: ``boolean`` **default**: ``true``

This option is useful when using the `allow_add`_ option. If ``true`` (and
if `allow_add`_ is also ``true``), a special "prototype" attribute will be
available so that you can render a "template" example on your page of what
a new element should look like. The ``name`` attribute given to this element
is ``__name__``. This allows you to add a "add another" button via JavaScript
which reads the prototype, replaces ``__name__`` with some unique name or
number, and render it inside your form. When submitted, it will be added
to your underlying array due to the `allow_add`_ option.
if `allow_add`_ is also ``true``), a special "prototype" attribute will
be available so that you can render a "template" example on your page of
what a new element should look like. The ``name`` attribute given to this
element is ``__name__``. This allows you to add a "add another" button via
JavaScript which reads the prototype, replaces ``__name__`` with some unique
name or number and render it inside your form. When submitted, it will
be added to your underlying array due to the `allow_add`_ option.

The prototype field can be rendered via the ``prototype`` variable in the
collection field:
Expand All @@ -313,34 +321,35 @@ rendering your form, having the entire "form row" may be easier for you.
form row is automatically available on the ``data-prototype`` attribute
of the element (e.g. ``div`` or ``table``) that surrounds your collection.

For details on how to actually use this option, see the above example as well
as :ref:`cookbook-form-collections-new-prototype`.
For details on how to actually use this option, see the above example as
well as :ref:`cookbook-form-collections-new-prototype`.

prototype_name
~~~~~~~~~~~~~~

**type**: ``String`` **default**: ``__name__``

If you have several collections in your form, or worse, nested collections
you may want to change the placeholder so that unrelated placeholders are not
replaced with the same value.
you may want to change the placeholder so that unrelated placeholders are
not replaced with the same value.

type
~~~~

**type**: ``string`` or :class:`Symfony\\Component\\Form\\FormTypeInterface` **required**

This is the field type for each item in this collection (e.g. ``text``, ``choice``,
etc). For example, if you have an array of email addresses, you'd use the
:doc:`email </reference/forms/types/email>` type. If you want to embed
a collection of some other form, create a new instance of your form type
and pass it as this option.
This is the field type for each item in this collection (e.g. ``text``,
``choice``, etc). For example, if you have an array of email addresses,
you'd use the :doc:`email </reference/forms/types/email>` type. If you want
to embed a collection of some other form, create a new instance of your
form type and pass it as this option.

Inherited Options
-----------------

These options inherit from the :doc:`form </reference/forms/types/form>` type.
Not all options are listed here - only the most applicable to this type:
These options inherit from the :doc:`form </reference/forms/types/form>`
type. Not all options are listed here - only the most applicable to this
type:

.. _reference-form-types-by-reference:

Expand Down
10 changes: 6 additions & 4 deletions reference/forms/types/country.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ country Field Type
==================

The ``country`` type is a subset of the ``ChoiceType`` that displays countries
of the world. As an added bonus, the country names are displayed in the language
of the user.
of the world. As an added bonus, the country names are displayed in the
language of the user.

The "value" for each country is the two-letter country code.

Expand Down Expand Up @@ -64,7 +64,8 @@ The locale is used to translate the countries names.
Inherited Options
-----------------

These options inherit from the :doc:`choice </reference/forms/types/choice>` type:
These options inherit from the :doc:`choice </reference/forms/types/choice>`
type:

.. include:: /reference/forms/types/options/empty_value.rst.inc

Expand All @@ -78,7 +79,8 @@ These options inherit from the :doc:`choice </reference/forms/types/choice>` typ

.. include:: /reference/forms/types/options/preferred_choices.rst.inc

These options inherit from the :doc:`form </reference/forms/types/form>` type:
These options inherit from the :doc:`form </reference/forms/types/form>`
type:

.. include:: /reference/forms/types/options/data.rst.inc

Expand Down
16 changes: 9 additions & 7 deletions reference/forms/types/currency.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@ currency Field Type
===================

The ``currency`` type is a subset of the
:doc:`choice type </reference/forms/types/choice>` that allows the user to
select from a large list of `3-letter ISO 4217`_ currencies.
:doc:`choice type </reference/forms/types/choice>` that allows the user
to select from a large list of `3-letter ISO 4217`_ currencies.

Unlike the ``choice`` type, you don't need to specify a ``choices`` or
``choice_list`` option as the field type automatically uses a large list of
currencies. You *can* specify either of these options manually, but then you
should just use the ``choice`` type directly.
``choice_list`` option as the field type automatically uses a large list
of currencies. You *can* specify either of these options manually, but then
you should just use the ``choice`` type directly.

+-------------+------------------------------------------------------------------------+
| Rendered as | can be various tags (see :ref:`forms-reference-choice-tags`) |
Expand Down Expand Up @@ -56,7 +56,8 @@ The choices option defaults to all currencies.
Inherited Options
-----------------

These options inherit from the :doc:`choice</reference/forms/types/choice>` type:
These options inherit from the :doc:`choice</reference/forms/types/choice>`
type:

.. include:: /reference/forms/types/options/empty_value.rst.inc

Expand All @@ -68,7 +69,8 @@ These options inherit from the :doc:`choice</reference/forms/types/choice>` type

.. include:: /reference/forms/types/options/preferred_choices.rst.inc

These options inherit from the :doc:`form</reference/forms/types/form>` type:
These options inherit from the :doc:`form</reference/forms/types/form>`
type:

.. include:: /reference/forms/types/options/data.rst.inc

Expand Down
Loading

0 comments on commit 55246be

Please sign in to comment.