Permalink
Browse files

merged branch bschussek/issue6217-no-dots-between-date-fields (PR #6575)

This PR was merged into the master branch.

Commits
-------

e0b4480 [Form] Removed separator characters between choice or text fields in DateType

Discussion
----------

[Form] Removed separator characters between choice or text fields in DateType

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

This commit was originally contained in #6217 (for 2.1) but then split away for master since it changes behavior.
  • Loading branch information...
2 parents 5d5e0f4 + 5386e99 commit af76f44fac3dff0f64cfbb178ff7f5d45604bde8 @fabpot fabpot committed Jan 5, 2013
Showing with 23 additions and 5 deletions.
  1. +2 −0 CHANGELOG.md
  2. +6 −1 Extension/Core/Type/DateType.php
  3. +15 −4 Tests/Extension/Core/Type/DateTypeTest.php
View
@@ -7,6 +7,8 @@ CHANGELOG
* TrimListener now removes unicode whitespaces
* deprecated getParent(), setParent() and hasParent() in FormBuilderInterface
* FormInterface::add() now accepts a FormInterface instance OR a field's name, type and options
+ * removed special characters between the choice or text fields of DateType unless
+ the option "format" is set to a custom value
2.1.0
-----
@@ -137,13 +137,18 @@ public function finishView(FormView $view, FormInterface $form, array $options)
if ($form->getConfig()->hasAttribute('formatter')) {
$pattern = $form->getConfig()->getAttribute('formatter')->getPattern();
+ // remove special characters unless the format was explicitly specified
+ if (!is_string($options['format'])) {
+ $pattern = preg_replace('/[^yMd]+/', '', $pattern);
+ }
+
// set right order with respect to locale (e.g.: de_DE=dd.MM.yy; en_US=M/d/yy)
// lookup various formats at http://userguide.icu-project.org/formatparse/datetime
if (preg_match('/^([yMd]+).+([yMd]+).+([yMd]+)$/', $pattern)) {
$pattern = preg_replace(array('/y+/', '/M+/', '/d+/'), array('{{ year }}', '{{ month }}', '{{ day }}'), $pattern);
} else {
// default fallback
- $pattern = '{{ year }}-{{ month }}-{{ day }}';
+ $pattern = '{{ year }}{{ month }}{{ day }}';
}
$view->vars['date_pattern'] = $pattern;
@@ -28,7 +28,7 @@ protected function setUp()
*/
public function testInvalidWidgetOption()
{
- $form = $this->factory->create('date', null, array(
+ $this->factory->create('date', null, array(
'widget' => 'fake_widget',
));
}
@@ -38,7 +38,7 @@ public function testInvalidWidgetOption()
*/
public function testInvalidInputOption()
{
- $form = $this->factory->create('date', null, array(
+ $this->factory->create('date', null, array(
'input' => 'fake_input',
));
}
@@ -510,7 +510,7 @@ public function testPassDatePatternToView()
$form = $this->factory->create('date');
$view = $form->createView();
- $this->assertSame('{{ day }}.{{ month }}.{{ year }}', $view->vars['date_pattern']);
+ $this->assertSame('{{ day }}{{ month }}{{ year }}', $view->vars['date_pattern']);
}
public function testPassDatePatternToViewDifferentFormat()
@@ -521,12 +521,23 @@ public function testPassDatePatternToViewDifferentFormat()
$view = $form->createView();
- $this->assertSame('{{ day }}. {{ month }} {{ year }}', $view->vars['date_pattern']);
+ $this->assertSame('{{ day }}{{ month }}{{ year }}', $view->vars['date_pattern']);
}
public function testPassDatePatternToViewDifferentPattern()
{
$form = $this->factory->create('date', null, array(
+ 'format' => 'MMyyyydd'
+ ));
+
+ $view = $form->createView();
+
+ $this->assertSame('{{ month }}{{ year }}{{ day }}', $view->vars['date_pattern']);
+ }
+
+ public function testPassDatePatternToViewDifferentPatternWithSeparators()
+ {
+ $form = $this->factory->create('date', null, array(
'format' => 'MM*yyyy*dd'
));

0 comments on commit af76f44

Please sign in to comment.