Skip to content

Commit

Permalink
[Form] Adding an exception for an invalid widget option in DateType
Browse files Browse the repository at this point in the history
  • Loading branch information
weaverryan committed Apr 24, 2011
1 parent 81deedf commit 78b2062
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Symfony/Component/Form/Extension/Core/Type/DateType.php
Expand Up @@ -14,6 +14,7 @@
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\Form\FormBuilder;
use Symfony\Component\Form\Exception\FormException;
use Symfony\Component\Form\Extension\Core\ChoiceList\PaddedChoiceList;
use Symfony\Component\Form\Extension\Core\ChoiceList\MonthChoiceList;
use Symfony\Component\Form\FormView;
Expand All @@ -36,7 +37,7 @@ public function buildForm(FormBuilder $builder, array $options)

if ($options['widget'] === 'text') {
$builder->appendClientTransformer(new DateTimeToLocalizedStringTransformer($options['data_timezone'], $options['user_timezone'], $options['format'], \IntlDateFormatter::NONE));
} else {
} elseif ($options['widget'] == 'choice') {
// Only pass a subset of the options to children
$yearOptions = array(
'choice_list' => new PaddedChoiceList(
Expand All @@ -58,6 +59,8 @@ public function buildForm(FormBuilder $builder, array $options)
->add('month', 'choice', $monthOptions)
->add('day', 'choice', $dayOptions)
->appendClientTransformer(new DateTimeToArrayTransformer($options['data_timezone'], $options['user_timezone'], array('year', 'month', 'day')));
} else {
throw new FormException('The "widget" option must be set to either "text" or "choice".');
}

if ($options['input'] === 'string') {
Expand Down
Expand Up @@ -25,6 +25,16 @@ protected function setUp()
\Locale::setDefault('de_AT');
}

/**
* @expectedException Symfony\Component\Form\Exception\FormException
*/
public function testInvalidWidgetOption()
{
$form = $this->factory->create('date', 'name', array(
'widget' => 'fake_widget',
));
}

public function testSubmitFromInputDateTime()
{
$form = $this->factory->create('date', null, array(
Expand Down

0 comments on commit 78b2062

Please sign in to comment.