-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Repeated field type required
is a required option
#11694
Comments
My exact usecase is this. The form type: class UserType extends AbstractAPIType
{
/**
* @param FormBuilderInterface $builder
* @param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('email', 'email', [])
->add('username', 'text', [])
->add('password', 'repeated', [
'type' => 'password',
'required' => true,
'first_options' => 'Password',
'second_options' => 'Password (again)',
])
;
}
} ...extending this simple wrapper class AbstractAPIType extends AbstractType
{
/**
* Returns the name of this type.
*
* @return string The name of this type
*/
final public function getName()
{
return '';
}
/**
* @param OptionsResolverInterface $resolver
*/
public function setDefaultOptions(OptionsResolverInterface $resolver)
{
$resolver
->setDefaults(['csrf_protection' => false])
;
}
} ...throws an error in a test: class UserTypeTest extends TypeTestCase
{
public function testSubmitValidData()
{
$formData = [
'email' => 'email@mail.com',
'name' => 'test user',
'password' => '12345',
];
$type = new UserType();
$form = $this->factory->create($type);
$form->submit($formData);
$this->assertInstanceOf(User::class, $form->getData());
$view = $form->createView();
$children = $view->children;
foreach (array_keys($formData) as $key) {
$this->assertArrayHasKey($key, $children);
}
}
} The trace and the error:
|
The |
@stof, no, there isn't any form type that would do this; I've also tried commenting out all of the non-standard bundles, the error is still there. |
@stof, well, it's actually a bit more funny: I've been passing the labels like this: 'first_options' => 'Password', So the Adding this into $resolver->setAllowedTypes(array(
'first_options' => 'array',
'second_options' => 'array',
)); |
I'll try to cover this with tests and issue a PR now, I think the issue is pretty obvious now. |
hmm, the right fix is indeed to add the allowed types for these 2 options to enforce passing an array |
This is resolved, no need to widen the scope I think. |
…me form types (kix) This PR was submitted for the master branch but it was merged into the 2.3 branch instead (closes #11696). Discussion ---------- [Form] Fix #11694 - Enforce options value type check in some form types | Q | A | ------------- | --- | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #11694 | License | MIT | Doc PR | none `Symfony\Component\Form\Extension\Core\Type\RepeatedType` allowed passing strings as options, which caused problems as in #11694. Commits ------- 0af6467 [Form] Fix #11694 - Enforce options value type check in some form types
Fixed in #11696. |
* 2.3: enforce memcached version to be 2.1.0 [FrameworkBundle] improve server:run feedback [Form] no need to add the url listener when it does not do anything [Form] Fix #11694 - Enforce options value type check in some form types Lithuanian security translations [Router] Cleanup [FrameworkBundle] Fixed ide links Add missing argument [TwigBundle] do not pass a template reference to twig [TwigBundle] show correct fallback exception template in debug mode [TwigBundle] remove unused email placeholder from error page use meta charset in layouts without legacy http-equiv Conflicts: src/Symfony/Bundle/TwigBundle/Loader/FilesystemLoader.php src/Symfony/Bundle/TwigBundle/Resources/views/layout.html.twig
* 2.5: enforce memcached version to be 2.1.0 [PropertyAccess] Simplified code [FrameworkBundle] improve server:run feedback [Form] no need to add the url listener when it does not do anything [Form] Fix #11694 - Enforce options value type check in some form types Lithuanian security translations [SecurityBundle] Add trust_resolver variable into expression | Q | A | ------------- | --- | Bug fix? | [yes] | New feature? | [no] | BC breaks? | [no] | Deprecations? | [no] | Tests pass? | [yes] | Fixed tickets | [#12224] | License | MIT | Doc PR | [-] [Router] Cleanup Fixed UPGRADE-3.0.md markup [FrameworkBundle] Fixed ide links Add missing argument [TwigBundle] do not pass a template reference to twig [TwigBundle] show correct fallback exception template in debug mode [TwigBundle] remove unused email placeholder from error page use meta charset in layouts without legacy http-equiv Conflicts: src/Symfony/Bundle/TwigBundle/Controller/ExceptionController.php
The
Symfony\Component\Form\Extension\Core\Type\RepeatedType
throwsIllegal string offset 'required'
when arequired
option is not passed to the form builder. Could this be resolved via theOptionsResolverInterface::setRequired()
method call in theRepeatedType::setDefaultOptions
method?The text was updated successfully, but these errors were encountered: