Skip to content

[Form] "Expected argument of type "array or (\Traversable and \ArrayAccess)", "string" given" #15023

@s-code

Description

@s-code

Hello,

I get the message:

"Expected argument of type "array or (\Traversable and \ArrayAccess)", "string" given"
in vendor/symfony/symfony/src/Symfony/Component/Form/Extension/Core/EventListener/ResizeFormListener.php at line 110

if (!is_array($data) && !($data instanceof \Traversable && $data instanceof \ArrayAccess)) {
      throw new UnexpectedTypeException($data, 'array or (\Traversable and \ArrayAccess)');
}

during the execution of this code:

$form = $this->createFormBuilder([], ['csrf_protection' => false])
->add('collectionField', 'collection', ['type' => 'text', 'constraints' => [new Type('array')]])
->add('integerField', 'integer', ['constraints' => [new Type('integer')]])
->getForm();

$form->submit(['collectionField' => 'error', 'integerField' => 'error']);

This is because i pass string data to "collectionField" field.

But when i pass array to "integerField":

$form->submit(['collectionField' => [], 'integerField' => []]);

i get normal message "This value is not valid.".

I think behaviour should be the same. Or maybe i missed something. Thx

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions