diff --git a/UPDATE.md b/UPDATE.md
index 2f96877632..844d44cfc5 100644
--- a/UPDATE.md
+++ b/UPDATE.md
@@ -139,6 +139,10 @@ beta1 to beta2
* Serializer: The `$properties` argument has been dropped from all interfaces.
+* Form: Renamed option value "text" of "widget" option of the "date" type was
+ renamed to "single-text". "text" indicates to use separate text boxes now
+ (like for the "time" type).
+
PR12 to beta1
-------------
diff --git a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/date_widget.html.php b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/date_widget.html.php
index a71e9b4059..583c881e3f 100644
--- a/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/date_widget.html.php
+++ b/src/Symfony/Bundle/FrameworkBundle/Resources/views/Form/date_widget.html.php
@@ -1,4 +1,4 @@
-
+
attributes() ?>
name="escape($name) ?>"
diff --git a/src/Symfony/Bundle/TwigBundle/Resources/views/Form/div_layout.html.twig b/src/Symfony/Bundle/TwigBundle/Resources/views/Form/div_layout.html.twig
index 782a0a5006..6f8ba5b49d 100644
--- a/src/Symfony/Bundle/TwigBundle/Resources/views/Form/div_layout.html.twig
+++ b/src/Symfony/Bundle/TwigBundle/Resources/views/Form/div_layout.html.twig
@@ -151,7 +151,7 @@
{% block date_widget %}
{% spaceless %}
- {% if widget == 'text' %}
+ {% if widget == 'single-text' %}
{{ block('text_widget') }}
{% else %}
diff --git a/src/Symfony/Component/Form/Extension/Core/Type/DateType.php b/src/Symfony/Component/Form/Extension/Core/Type/DateType.php
index 5c19151350..565459b9b0 100644
--- a/src/Symfony/Component/Form/Extension/Core/Type/DateType.php
+++ b/src/Symfony/Component/Form/Extension/Core/Type/DateType.php
@@ -35,29 +35,34 @@ class DateType extends AbstractType
\DateTimeZone::UTC
);
- if ($options['widget'] === 'text') {
+ if ($options['widget'] === 'single-text') {
$builder->appendClientTransformer(new DateTimeToLocalizedStringTransformer($options['data_timezone'], $options['user_timezone'], $options['format'], \IntlDateFormatter::NONE));
} else {
- // Only pass a subset of the options to children
- $yearOptions = array(
- 'choice_list' => new PaddedChoiceList(
- array_combine($options['years'], $options['years']), 4, '0', STR_PAD_LEFT
- ),
- );
- $monthOptions = array(
- 'choice_list' => new MonthChoiceList(
- $formatter, $options['months']
- ),
- );
- $dayOptions = array(
- 'choice_list' => new PaddedChoiceList(
- array_combine($options['days'], $options['days']), 2, '0', STR_PAD_LEFT
- ),
- );
+ $yearOptions = $monthOptions = $dayOptions = array();
+ $widget = $options['widget'];
- $builder->add('year', 'choice', $yearOptions)
- ->add('month', 'choice', $monthOptions)
- ->add('day', 'choice', $dayOptions)
+ if ($widget === 'choice') {
+ // Only pass a subset of the options to children
+ $yearOptions = array(
+ 'choice_list' => new PaddedChoiceList(
+ array_combine($options['years'], $options['years']), 4, '0', STR_PAD_LEFT
+ ),
+ );
+ $monthOptions = array(
+ 'choice_list' => new MonthChoiceList(
+ $formatter, $options['months']
+ ),
+ );
+ $dayOptions = array(
+ 'choice_list' => new PaddedChoiceList(
+ array_combine($options['days'], $options['days']), 2, '0', STR_PAD_LEFT
+ ),
+ );
+ }
+
+ $builder->add('year', $widget, $yearOptions)
+ ->add('month', $widget, $monthOptions)
+ ->add('day', $widget, $dayOptions)
->appendClientTransformer(new DateTimeToArrayTransformer($options['data_timezone'], $options['user_timezone'], array('year', 'month', 'day')));
}
@@ -132,6 +137,7 @@ class DateType extends AbstractType
'array',
),
'widget' => array(
+ 'single-text',
'text',
'choice',
),
@@ -146,7 +152,7 @@ class DateType extends AbstractType
public function getParent(array $options)
{
- return $options['widget'] === 'text' ? 'field' : 'form';
+ return $options['widget'] === 'single-text' ? 'field' : 'form';
}
public function getName()
diff --git a/tests/Symfony/Tests/Component/Form/AbstractLayoutTest.php b/tests/Symfony/Tests/Component/Form/AbstractLayoutTest.php
index 63248687a6..338b165b24 100644
--- a/tests/Symfony/Tests/Component/Form/AbstractLayoutTest.php
+++ b/tests/Symfony/Tests/Component/Form/AbstractLayoutTest.php
@@ -597,6 +597,35 @@ abstract class AbstractLayoutTest extends \PHPUnit_Framework_TestCase
'widget' => 'text',
));
+ $this->assertWidgetMatchesXpath($form->createView(), array(),
+'/div
+ [
+ ./input
+ [@id="na&me_month"]
+ [@type="text"]
+ [@value="2"]
+ /following-sibling::input
+ [@id="na&me_day"]
+ [@type="text"]
+ [@value="3"]
+ /following-sibling::input
+ [@id="na&me_year"]
+ [@type="text"]
+ [@value="2011"]
+ ]
+ [count(./input)=3]
+'
+ );
+ }
+
+ public function testDateSingleText()
+ {
+ $form = $this->factory->createNamed('date', 'na&me', '2011-02-03', array(
+ 'property_path' => 'name',
+ 'input' => 'string',
+ 'widget' => 'single-text',
+ ));
+
$this->assertWidgetMatchesXpath($form->createView(), array(),
'/input
[@type="text"]
diff --git a/tests/Symfony/Tests/Component/Form/Extension/Core/Type/DateTypeTest.php b/tests/Symfony/Tests/Component/Form/Extension/Core/Type/DateTypeTest.php
index 3e910e93b6..d226e5598d 100644
--- a/tests/Symfony/Tests/Component/Form/Extension/Core/Type/DateTypeTest.php
+++ b/tests/Symfony/Tests/Component/Form/Extension/Core/Type/DateTypeTest.php
@@ -45,12 +45,12 @@ class DateTypeTest extends LocalizedTestCase
));
}
- public function testSubmitFromInputDateTime()
+ public function testSubmitFromSingleTextDateTime()
{
$form = $this->factory->create('date', null, array(
'data_timezone' => 'UTC',
'user_timezone' => 'UTC',
- 'widget' => 'text',
+ 'widget' => 'single-text',
'input' => 'datetime',
));
@@ -60,12 +60,12 @@ class DateTypeTest extends LocalizedTestCase
$this->assertEquals('02.06.2010', $form->getClientData());
}
- public function testSubmitFromInputString()
+ public function testSubmitFromSingleTextString()
{
$form = $this->factory->create('date', null, array(
'data_timezone' => 'UTC',
'user_timezone' => 'UTC',
- 'widget' => 'text',
+ 'widget' => 'single-text',
'input' => 'string',
));
@@ -75,12 +75,12 @@ class DateTypeTest extends LocalizedTestCase
$this->assertEquals('02.06.2010', $form->getClientData());
}
- public function testSubmitFromInputTimestamp()
+ public function testSubmitFromSingleTextTimestamp()
{
$form = $this->factory->create('date', null, array(
'data_timezone' => 'UTC',
'user_timezone' => 'UTC',
- 'widget' => 'text',
+ 'widget' => 'single-text',
'input' => 'timestamp',
));
@@ -92,12 +92,12 @@ class DateTypeTest extends LocalizedTestCase
$this->assertEquals('02.06.2010', $form->getClientData());
}
- public function testSubmitFromInputRaw()
+ public function testSubmitFromSingleTextRaw()
{
$form = $this->factory->create('date', null, array(
'data_timezone' => 'UTC',
'user_timezone' => 'UTC',
- 'widget' => 'text',
+ 'widget' => 'single-text',
'input' => 'array',
));
@@ -113,6 +113,28 @@ class DateTypeTest extends LocalizedTestCase
$this->assertEquals('02.06.2010', $form->getClientData());
}
+ public function testSubmitFromText()
+ {
+ $form = $this->factory->create('date', null, array(
+ 'data_timezone' => 'UTC',
+ 'user_timezone' => 'UTC',
+ 'widget' => 'text',
+ ));
+
+ $text = array(
+ 'day' => '2',
+ 'month' => '6',
+ 'year' => '2010',
+ );
+
+ $form->bind($text);
+
+ $dateTime = new \DateTime('2010-06-02 UTC');
+
+ $this->assertDateTimeEquals($dateTime, $form->getData());
+ $this->assertEquals($text, $form->getClientData());
+ }
+
public function testSubmitFromChoice()
{
$form = $this->factory->create('date', null, array(
@@ -163,7 +185,7 @@ class DateTypeTest extends LocalizedTestCase
'user_timezone' => 'Pacific/Tahiti',
// don't do this test with DateTime, because it leads to wrong results!
'input' => 'string',
- 'widget' => 'text',
+ 'widget' => 'single-text',
));
$form->setData('2010-06-02');
@@ -178,7 +200,7 @@ class DateTypeTest extends LocalizedTestCase
$form = $this->factory->create('date', null, array(
'data_timezone' => 'UTC',
'user_timezone' => 'UTC',
- 'widget' => 'text',
+ 'widget' => 'single-text',
'years' => array(2010, 2011),
));
@@ -194,7 +216,7 @@ class DateTypeTest extends LocalizedTestCase
$form = $this->factory->create('date', null, array(
'data_timezone' => 'UTC',
'user_timezone' => 'UTC',
- 'widget' => 'text',
+ 'widget' => 'single-text',
'years' => array(2010, 2011),
));
@@ -230,7 +252,7 @@ class DateTypeTest extends LocalizedTestCase
$form = $this->factory->create('date', null, array(
'data_timezone' => 'UTC',
'user_timezone' => 'UTC',
- 'widget' => 'text',
+ 'widget' => 'single-text',
'years' => array(2010, 2012),
));
@@ -246,7 +268,7 @@ class DateTypeTest extends LocalizedTestCase
$form = $this->factory->create('date', null, array(
'data_timezone' => 'UTC',
'user_timezone' => 'UTC',
- 'widget' => 'text',
+ 'widget' => 'single-text',
'months' => array(6, 7),
));
@@ -262,7 +284,7 @@ class DateTypeTest extends LocalizedTestCase
$form = $this->factory->create('date', null, array(
'data_timezone' => 'UTC',
'user_timezone' => 'UTC',
- 'widget' => 'text',
+ 'widget' => 'single-text',
'months' => array(6, 7),
));
@@ -298,7 +320,7 @@ class DateTypeTest extends LocalizedTestCase
$form = $this->factory->create('date', null, array(
'data_timezone' => 'UTC',
'user_timezone' => 'UTC',
- 'widget' => 'text',
+ 'widget' => 'single-text',
'months' => array(6, 8),
));
@@ -314,7 +336,7 @@ class DateTypeTest extends LocalizedTestCase
$form = $this->factory->create('date', null, array(
'data_timezone' => 'UTC',
'user_timezone' => 'UTC',
- 'widget' => 'text',
+ 'widget' => 'single-text',
'days' => array(6, 7),
));
@@ -330,7 +352,7 @@ class DateTypeTest extends LocalizedTestCase
$form = $this->factory->create('date', null, array(
'data_timezone' => 'UTC',
'user_timezone' => 'UTC',
- 'widget' => 'text',
+ 'widget' => 'single-text',
'days' => array(6, 7),
));
@@ -368,7 +390,7 @@ class DateTypeTest extends LocalizedTestCase
$form = $this->factory->create('date', null, array(
'data_timezone' => 'UTC',
'user_timezone' => 'UTC',
- 'widget' => 'text',
+ 'widget' => 'single-text',
'days' => array(6, 8),
));
@@ -377,14 +399,14 @@ class DateTypeTest extends LocalizedTestCase
$this->assertFalse($form->isDayWithinRange());
}
- public function testIsPartiallyFilledReturnsFalseIfInput()
+ public function testIsPartiallyFilledReturnsFalseIfSingleText()
{
$this->markTestIncomplete('Needs to be reimplemented using validators');
$form = $this->factory->create('date', null, array(
'data_timezone' => 'UTC',
'user_timezone' => 'UTC',
- 'widget' => 'text',
+ 'widget' => 'single-text',
));
$form->bind('7.6.2010');
@@ -460,7 +482,7 @@ class DateTypeTest extends LocalizedTestCase
public function testDontPassDatePatternIfText()
{
$form = $this->factory->create('date', null, array(
- 'widget' => 'text',
+ 'widget' => 'single-text',
));
$view = $form->createView();
@@ -470,10 +492,10 @@ class DateTypeTest extends LocalizedTestCase
public function testPassWidgetToView()
{
$form = $this->factory->create('date', null, array(
- 'widget' => 'text',
+ 'widget' => 'single-text',
));
$view = $form->createView();
- $this->assertSame('text', $view->get('widget'));
+ $this->assertSame('single-text', $view->get('widget'));
}
}