symfony/symfony — pull request #3825 by ruimarinho (2012-04-07 20:10:33+00:00)
Title: [Form] Enhanced DateType with support for different widgets types per date part (year, month, day)

Bug fix: yes
Feature addition: yes
Backwards compatibility break: no
Symfony2 tests pass: ![Build status](https://secure.travis-ci.org/ruimarinho/symfony.png?branch=date_type)
Fixes the following tickets: #3490
Todo: discuss with @bschussek if it is possible to add support for padded dates per date type (not just globally, as it is now).

The _DateType_ widget is incredibly powerful it offers developers a wealth of features and customization options. This PR builds on this work and adds some extra flexibility to this widget, without compromising BC:

**Features**:

* The `widget` option now accepts an array for `year`, `month` and `day` date parts, which allows you to have something like a `choice` widget for `month` and `text` widgets for `year` and `day`. It defaults to `choice` if any of those parts is missing when using the array format.

* Developers can now pass options for each of the date parts widgets - `year_options`, `month_options` and `day_options`. A typical use case is passing an attribute like `data-mask` to control user input client side using JavaScript masks.

* Choose to pad dates or not - currently, dates are always displayed with the padded format (see issue #3490), although this behavior is not really consistent since the `DateTimeToArrayTransformer` defaults to not pad dates. What happens is that when using `choice` widgets, the value is casted to _int_ and it removes the padding, but the representation on the HTML still shows the padded date. This PR changes this by passing the correct padding option to the transform so that the output is either completely padded or not (both the `value` and its representation). This can be passed through the widget `options` option (`padded`: _boolean_).

Tests were added for these new features. The build fails but it's due to a patch not yet merged from the 2.0 branch.