8000 [Form] Removed separator characters between choice or text fields in … · symfony/symfony@e0b4480 · GitHub
[go: up one dir, main page]

Skip to content

Commit e0b4480

Browse files
committed
[Form] Removed separator characters between choice or text fields in DateType
1 parent 31ff3db commit e0b4480

File tree

3 files changed

+29
-11
lines changed

3 files changed

+29
-11
lines changed

src/Symfony/Component/Form/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ CHANGELOG
77
* TrimListener now removes unicode whitespaces
88
* deprecated getParent(), setParent() and hasParent() in FormBuilderInterface
99
* FormInterface::add() now accepts a FormInterface instance OR a field's name, type and options
10+
* removed special characters between the choice or text fields of DateType unless
11+
the option "format" is set to a custom value
1012

1113
2.1.0
1214
-----

src/Symfony/Component/Form/Extension/Core/Type/DateType.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,13 +137,18 @@ public function finishView(FormView $view, FormInterface $form, array $options)
137137
if ($form->getConfig()->hasAttribute('formatter')) {
138138
$pattern = $form->getConfig()->getAttribute('formatter')->getPattern();
139139

140+
// remove special characters unless the format was explicitly specified
141+
if (!is_string($options['format'])) {
142+
$pattern = preg_replace('/[^yMd]+/', '', $pattern);
143+
}
144+
140145
// set right order with respect to locale (e.g.: de_DE=dd.MM.yy; en_US=M/d/yy)
141146
// lookup various formats at http://userguide.icu-project.org/formatparse/datetime
142147
if (preg_match('/^([yMd]+).+([yMd]+).+([yMd]+)$/', $pattern)) {
143148
$pattern = preg_replace(array('/y+/', '/M+/', '/d+/'), array('{{ year }}', '{{ month }}', '{{ day }}'), $pattern);
144149
} else {
145150
// default fallback
146-
$pattern = '{{ year }}-{{ month }}-{{ day }}';
151+
$pattern = '{{ year }}{{ month }}{{ day }}';
147152
}
148153

149154
$view->vars['date_pattern'] = $pattern;

src/Symfony/Component/Form/Tests/Extension/Core/Type/DateTypeTest.php

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,21 @@ protected function setUp()
2424
}
2525

2626
/**
27-
* @expectedException Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
27+
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
2828
*/
2929
public function testInvalidWidgetOption()
3030
{
31-
$form = $this->factory->create('date', null, array(
31+
$this->factory->create('date', null, array(
3232
'widget' => 'fake_widget',
3333
));
3434
}
3535

3636
/**
37-
* @expectedException Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
37+
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
3838
*/
3939
public function testInvalidInputOption()
4040
{
41-
$form = $this->factory->create('date', null, array(
41+
$this->factory->create('date', null, array(
4242
'input' => 'fake_input',
4343
));
4444
}
@@ -271,7 +271,7 @@ public function testSubmitFromInputRawDifferentPattern()
271271
* This test is to check that the strings '0', '1', '2', '3' are no accepted
272272
* as valid IntlDateFormatter constants for FULL, LONG, MEDIUM or SHORT respectively.
273273
*
274-
* @expectedException Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
274+
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
275275
*/
276276
public function testThrowExceptionIfFormatIsNoPattern()
277277
{
@@ -283,7 +283,7 @@ public function testThrowExceptionIfFormatIsNoPattern()
283283
}
284284

285285
/**
286-
* @expectedException Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
286+
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
287287
*/
288288
public function testThrowExceptionIfFormatDoesNotContainYearMonthAndDay()
289289
{
@@ -294,7 +294,7 @@ public function testThrowExceptionIfFormatDoesNotContainYearMonthAndDay()
294294
}
295295

296296
/**
297-
* @expectedException Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
297+
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
298298
*/
299299
public function testThrowExceptionIfFormatIsNoConstant()
300300
{
@@ -304,7 +304,7 @@ public function testThrowExceptionIfFormatIsNoConstant()
304304
}
305305

306306
/**
307-
* @expectedException Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
307+
* @expectedException \Symfony\Component\OptionsResolver\Exception\InvalidOptionsException
308308
*/
309309
public function testThrowExceptionIfFormatIsInvalid()
310310
{
@@ -510,7 +510,7 @@ public function testPassDatePatternToView()
510510
$form = $this->factory->create('date');
511511
$view = $form->createView();
512512

513-
$this->assertSame('{{ day }}.{{ month }}.{{ year }}', $view->vars['date_pattern']);
513+
$this->assertSame('{{ day }}{{ month }}{{ year }}', $view->vars['date_pattern']);
514514
}
515515

516516
public function testPassDatePatternToViewDifferentFormat()
@@ -521,10 +521,21 @@ public function testPassDatePatternToViewDifferentFormat()
521521

522522
$view = $form->createView();
523523

524-
$this->assertSame('{{ day }}. {{ month }} {{ year }}', $view->vars['date_pattern']);
524+
$this->assertSame('{{ day }}{{ month }}{{ year }}', $view->vars['date_pattern']);
525525
}
526526

527527
public function testPassDatePatternToViewDifferentPattern()
528+
{
529+
$form = $this->factory->create('date', null, array(
530+
'format' => 'MMyyyydd'
531+
));
532+
533+
$view = $form->createView();
534+
535+
$this->assertSame('{{ month }}{{ year }}{{ day }}', $view->vars['date_pattern']);
536+
}
537+
538+
public function testPassDatePatternToViewDifferentPatternWithSeparators()
528539
{
529540
$form = $this->factory->create('date', null, array(
530541
'format' => 'MM*yyyy*dd'

0 commit comments

Comments
 (0)
0