Browse Source

merged branch beberlei/ChoiceFix (PR #1531)

Commits
-------

03fee4f Fix permissions
431460f [Form] Remove choice or choice_list requirement as the following conditions already check enough and this condition prevents empty select forms (populated by ajax for example)

Discussion
----------

[Form] Choice fix

[Form] Remove choice or choice_list requirement as the following conditions already check enough and this condition prevents empty select forms (populated by ajax for example)

---------------------------------------------------------------------------

by stloyd at 2011/07/05 06:26:36 -0700

You should revert permission changes.

---------------------------------------------------------------------------

by fabpot at 2011/07/05 06:28:14 -0700

Why not replacing `if (!$options['choices'] && !$options['choice_list']) {` by `if (!isset($options['choices']) && !isset($options['choice_list'])) { `?

---------------------------------------------------------------------------

by beberlei at 2011/07/05 06:35:50 -0700

gnaa permission changes, i cant seem to configure my machine such that it does not do it, i have to do this on a per repository basis, very annoying.

@fabpot isset() is already guaranteed because these two options are in the defaults.

---------------------------------------------------------------------------

by beberlei at 2011/07/05 06:39:43 -0700

Fixed the permissions

---------------------------------------------------------------------------

by stof at 2011/07/05 06:48:37 -0700

@beberlei Can't you fix it in the global git config ?

---------------------------------------------------------------------------

by webda2l at 2011/07/05 09:48:58 -0700

I met the same problem this afternoon and vote for the isset solution. Better than nothing and work for me.
https://github.com/symfony/symfony/pull/1539

---------------------------------------------------------------------------

by stof at 2011/07/05 09:50:09 -0700

@webda2l why is a check that always return true better than nothing ? It adds overhead without adding any value in the code.
Fabien Potencier 14 years ago
parent
commit
c814d4ce9c

+ 0 - 4
src/Symfony/Component/Form/Extension/Core/Type/ChoiceType.php

@@ -31,10 +31,6 @@ class ChoiceType extends AbstractType
      */
     public function buildForm(FormBuilder $builder, array $options)
     {
-        if (!$options['choices'] && !$options['choice_list']) {
-            throw new FormException('Either the option "choices" or "choice_list" is required');
-        }
-
         if ($options['choice_list'] && !$options['choice_list'] instanceof ChoiceListInterface) {
             throw new FormException('The "choice_list" must be an instance of "Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceListInterface".');
         }

+ 0 - 8
tests/Symfony/Tests/Component/Form/Extension/Core/Type/ChoiceTypeTest.php

@@ -303,14 +303,6 @@ class ChoiceTypeTest extends TypeTestCase
         $this->assertEquals(array('0', '1'), $form->getClientData());
     }
 
-    /**
-     * @expectedException Symfony\Component\Form\Exception\FormException
-     */
-    public function testRequiresChoicesOrChoiceListOption()
-    {
-        $this->factory->create('choice', 'name');
-    }
-
     public function testPassRequiredToView()
     {
         $form = $this->factory->create('choice', null, array(