Skip to content
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

Initial Values Normalizer produces StdClass instead of Array for collections #29

Open
jakub-zawislak opened this issue May 15, 2018 · 1 comment

Comments

@jakub-zawislak
Copy link

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);
@hugoalexmartins
Copy link

hugoalexmartins commented Sep 6, 2018

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 !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants