merged branch bschussek/issue6141_2 (PR #6217)

This PR was merged into the 2.1 branch.

Commits
-------

6e7e08f [Form] Fixed the default value of "format" in DateType to DateType::DEFAULT_FORMAT if "widget" is not "single_text"

Discussion
----------

[Form] Fixed the "format" option in DateType

Bug fix: yes
Feature addition: no
Backwards compatibility break: no
Symfony2 tests pass: yes
Fixes the following tickets: #6141
Todo: -
License of the code: MIT
Documentation PR: -

This PR fixes a regression introduced in #4839. To quote that PR:

> This PR changes DateType and DateTimeType to support HTML5 by default when setting the option "widget" to "single_text".

In reality, the "format" option now defaults to the HTML5 format always, not just when "widget" is "single_text". This is fixed here.

The second commit in this PR removes special characters between select/text fields. What, with German locale, was

```
<day input>.<month input>.<year input>
```

before is now

```
<day input><month input><year input>
```

This is the way date fields are represented on the majority of websites. If you *need* separators, you can have them by setting the "format" option to a custom value:

```php
$builder->add('myDate', 'date', array(
    'format' => 'dd.MM.yyyy',
));
```

---------------------------------------------------------------------------

by fabpot at 2012-12-07T08:52:21Z

The second commit should probably be done on master and it changes the behavior.

---------------------------------------------------------------------------

by bschussek at 2012-12-07T12:23:22Z

Ok, I removed the second commit now and removed the entries from the CHANGELOG.
This commit is contained in:
Fabien Potencier 2012-12-07 14:34:54 +01:00
commit 74c8b0150a
3 changed files with 40 additions and 36 deletions

View File

@ -180,6 +180,10 @@ class DateType extends AbstractType
);
};
$format = function (Options $options) {
return $options['widget'] === 'single_text' ? self::HTML5_FORMAT : self::DEFAULT_FORMAT;
};
// BC until Symfony 2.3
$modelTimezone = function (Options $options) {
return $options['data_timezone'];
@ -196,7 +200,7 @@ class DateType extends AbstractType
'days' => range(1, 31),
'widget' => 'choice',
'input' => 'datetime',
'format' => self::HTML5_FORMAT,
'format' => $format,
'model_timezone' => $modelTimezone,
'view_timezone' => $viewTimezone,
// Deprecated timezone options

View File

@ -809,14 +809,14 @@ abstract class AbstractLayoutTest extends FormIntegrationTestCase
[@id="name_date"]
[
./select
[@id="name_date_year"]
[./option[@value="2011"][@selected="selected"]]
/following-sibling::select
[@id="name_date_month"]
[./option[@value="2"][@selected="selected"]]
/following-sibling::select
[@id="name_date_day"]
[./option[@value="3"][@selected="selected"]]
/following-sibling::select
[@id="name_date_year"]
[./option[@value="2011"][@selected="selected"]]
]
/following-sibling::div
[@id="name_time"]
@ -849,14 +849,14 @@ abstract class AbstractLayoutTest extends FormIntegrationTestCase
[@id="name_date"]
[
./select
[@id="name_date_year"]
[./option[@value=""][.="[trans]Change&Me[/trans]"]]
/following-sibling::select
[@id="name_date_month"]
[./option[@value=""][.="[trans]Change&Me[/trans]"]]
/following-sibling::select
[@id="name_date_day"]
[./option[@value=""][.="[trans]Change&Me[/trans]"]]
/following-sibling::select
[@id="name_date_year"]
[./option[@value=""][.="[trans]Change&Me[/trans]"]]
]
/following-sibling::div
[@id="name_time"]
@ -889,14 +889,14 @@ abstract class AbstractLayoutTest extends FormIntegrationTestCase
[@id="name_date"]
[
./select
[@id="name_date_year"]
[./option[@value="2011"][@selected="selected"]]
/following-sibling::select
[@id="name_date_month"]
[./option[@value="2"][@selected="selected"]]
/following-sibling::select
[@id="name_date_day"]
[./option[@value="3"][@selected="selected"]]
/following-sibling::select
[@id="name_date_year"]
[./option[@value="2011"][@selected="selected"]]
]
/following-sibling::div
[@id="name_time"]
@ -928,14 +928,14 @@ abstract class AbstractLayoutTest extends FormIntegrationTestCase
[@id="name_date"]
[
./select
[@id="name_date_year"]
[./option[@value="2011"][@selected="selected"]]
/following-sibling::select
[@id="name_date_month"]
[./option[@value="2"][@selected="selected"]]
/following-sibling::select
[@id="name_date_day"]
[./option[@value="3"][@selected="selected"]]
/following-sibling::select
[@id="name_date_year"]
[./option[@value="2011"][@selected="selected"]]
]
/following-sibling::div
[@id="name_time"]
@ -1031,14 +1031,14 @@ abstract class AbstractLayoutTest extends FormIntegrationTestCase
'/div
[
./select
[@id="name_year"]
[./option[@value="2011"][@selected="selected"]]
/following-sibling::select
[@id="name_month"]
[./option[@value="2"][@selected="selected"]]
/following-sibling::select
[@id="name_day"]
[./option[@value="3"][@selected="selected"]]
/following-sibling::select
[@id="name_year"]
[./option[@value="2011"][@selected="selected"]]
]
[count(./select)=3]
'
@ -1058,14 +1058,14 @@ abstract class AbstractLayoutTest extends FormIntegrationTestCase
'/div
[
./select
[@id="name_year"]
[./option[@value=""][.="[trans]Change&Me[/trans]"]]
/following-sibling::select
[@id="name_month"]
[./option[@value=""][.="[trans]Change&Me[/trans]"]]
/following-sibling::select
[@id="name_day"]
[./option[@value=""][.="[trans]Change&Me[/trans]"]]
/following-sibling::select
[@id="name_year"]
[./option[@value=""][.="[trans]Change&Me[/trans]"]]
]
[count(./select)=3]
'
@ -1085,14 +1085,14 @@ abstract class AbstractLayoutTest extends FormIntegrationTestCase
'/div
[
./select
[@id="name_year"]
[./option[@value=""][.="[trans]Change&Me[/trans]"]]
/following-sibling::select
[@id="name_month"]
[./option[@value="1"]]
/following-sibling::select
[@id="name_day"]
[./option[@value="1"]]
/following-sibling::select
[@id="name_year"]
[./option[@value=""][.="[trans]Change&Me[/trans]"]]
]
[count(./select)=3]
'
@ -1110,10 +1110,6 @@ abstract class AbstractLayoutTest extends FormIntegrationTestCase
'/div
[
./input
[@id="name_year"]
[@type="text"]
[@value="2011"]
/following-sibling::input
[@id="name_month"]
[@type="text"]
[@value="2"]
@ -1121,6 +1117,10 @@ abstract class AbstractLayoutTest extends FormIntegrationTestCase
[@id="name_day"]
[@type="text"]
[@value="3"]
/following-sibling::input
[@id="name_year"]
[@type="text"]
[@value="2011"]
]
[count(./input)=3]
'
@ -1164,14 +1164,14 @@ abstract class AbstractLayoutTest extends FormIntegrationTestCase
'/div
[
./select
[@id="name_year"]
[./option[@value="2000"][@selected="selected"]]
/following-sibling::select
[@id="name_month"]
[./option[@value="2"][@selected="selected"]]
/following-sibling::select
[@id="name_day"]
[./option[@value="3"][@selected="selected"]]
/following-sibling::select
[@id="name_year"]
[./option[@value="2000"][@selected="selected"]]
]
[count(./select)=3]
'
@ -1190,10 +1190,6 @@ abstract class AbstractLayoutTest extends FormIntegrationTestCase
'/div
[
./select
[@id="name_year"]
[./option[@value=""][.="[trans][/trans]"]]
[./option[@value="1950"][@selected="selected"]]
/following-sibling::select
[@id="name_month"]
[./option[@value=""][.="[trans][/trans]"]]
[./option[@value="1"][@selected="selected"]]
@ -1201,6 +1197,10 @@ abstract class AbstractLayoutTest extends FormIntegrationTestCase
[@id="name_day"]
[./option[@value=""][.="[trans][/trans]"]]
[./option[@value="1"][@selected="selected"]]
/following-sibling::select
[@id="name_year"]
[./option[@value=""][.="[trans][/trans]"]]
[./option[@value="1950"][@selected="selected"]]
]
[count(./select)=3]
'

View File

@ -510,18 +510,18 @@ class DateTypeTest extends LocalizedTestCase
$form = $this->factory->create('date');
$view = $form->createView();
$this->assertSame('{{ year }}-{{ month }}-{{ day }}', $view->vars['date_pattern']);
$this->assertSame('{{ day }}.{{ month }}.{{ year }}', $view->vars['date_pattern']);
}
public function testPassDatePatternToViewDifferentFormat()
{
$form = $this->factory->create('date', null, array(
'format' => \IntlDateFormatter::MEDIUM,
'format' => \IntlDateFormatter::LONG,
));
$view = $form->createView();
$this->assertSame('{{ day }}.{{ month }}.{{ year }}', $view->vars['date_pattern']);
$this->assertSame('{{ day }}. {{ month }} {{ year }}', $view->vars['date_pattern']);
}
public function testPassDatePatternToViewDifferentPattern()