Initial Values Normalizer produces StdClass instead of Array for collections
jakub-zawislak opened this issue · comments
Symfony 2.8
I have a form:
$builder->add('name', TextType::class);
$builder->add('contacts', CollectionType::class, [...]);
The normalizer produces this output:
stdClass Object
(
[name] => Test
[contacts] => stdClass Object
(
[0] => stdClass Object
(
[value] => TestValue
)
)
)
instead of:
stdClass Object
(
[name] => Test
[contacts] => Array <--------- array
(
[0] => stdClass Object
(
[value] => TestValue
)
)
)
I'm passing this data to a JS in this way inside <script>
in .twig
:
window.form.initialValues = {{ initialValues|json_encode|raw }}
stdClass and Array are different in JSON format. stdClass gives {0: item}
instead of [item]
.
As a result I have error while using liform-react
in ConnectedFieldArray.js:83
nextValue.every is not a function
When I hardcoded StdClass -> Array conversion, all works
$initialValues->contacts = json_decode(json_encode($initialValues->contacts), true);
Hi @jakub-zawislak ,
I'm having a hard time
I'm trying to implement a collection type, but the output just gives me the first row of the collection.
Any idea what this problem might be?
My output is just this:
{
"schema": {
"title": "visaexpress_wizardbundle_wizard",
"type": "object",
"properties": {
"wizard_questions": {
"type": "array",
"title": "wizard_questions",
"items": {
"title": "0",
"type": "object",
"properties": {
"question": {
"type": "string",
"title": "question",
"propertyOrder": 1
},
"helper": {
"type": "string",
"title": "helper",
"widget": "textarea",
"propertyOrder": 2
}
},
"required": [
"question"
]
},
"propertyOrder": 1
}
},
"required": [
"wizard_questions"
]
}
}
WizardQuestion have 5 rows !