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.
This commit is contained in:
commit
af070084d3
|
@ -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 @@ class DateType extends AbstractType
|
|||
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 @@ class DateTypeTest extends LocalizedTestCase
|
|||
*/
|
||||
public function testInvalidWidgetOption()
|
||||
{
|
||||
$form = $this->factory->create('date', null, array(
|
||||
$this->factory->create('date', null, array(
|
||||
'widget' => 'fake_widget',
|
||||
));
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ class DateTypeTest extends LocalizedTestCase
|
|||
*/
|
||||
public function testInvalidInputOption()
|
||||
{
|
||||
$form = $this->factory->create('date', null, array(
|
||||
$this->factory->create('date', null, array(
|
||||
'input' => 'fake_input',
|
||||
));
|
||||
}
|
||||
|
@ -510,7 +510,7 @@ class DateTypeTest extends LocalizedTestCase
|
|||
$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,10 +521,21 @@ class DateTypeTest extends LocalizedTestCase
|
|||
|
||||
$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'
|
||||
|
|
Reference in New Issue