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

Fix nested form data in Snowboard requests #1182

Merged
merged 4 commits into from
Aug 14, 2024

Conversation

bennothommo
Copy link
Member

This fix allows nested objects within the request data to be correctly converted to nested form data when sending the request.

Previously, if the data option in a Request contained nested objects or arrays within the data, these were being incorrectly converted to [Array array] or [Object object], as the FormData object would simply convert them to strings. With this fix, we traverse the data structure and ensure that they are given the right key in order to keep the shape of the data in the POST data.

@mjauvin
Copy link
Member

mjauvin commented Aug 13, 2024

@bennothommo that resolves the issue.

thanks.

@bennothommo
Copy link
Member Author

@mjauvin when you get a chance, could you give it one more test with the latest changes - I've just simplified the code a little.

@mjauvin
Copy link
Member

mjauvin commented Aug 13, 2024

@mjauvin when you get a chance, could you give it one more test with the latest changes - I've just simplified the code a little.

Looks good!

@mjauvin
Copy link
Member

mjauvin commented Aug 13, 2024

@bennothommo I tested with the data structure below:

$this['data'] = [
    'key' => 'value',
    'nested' => [
      'otherKey' => 'other value',
      'secondLevel' => [
        'moreLevels' => [       
          'third' => 'third level',
          'thirdObj' => (object)[
            'fourth' => 'fourth level',
          ],
        ],
        'second' => 'second level',
      ],
    ],
];

got the following result from the ajax handler:

[2024-08-13 14:31:12] dev.INFO: Array
(           
    [key] => value
    [nested] => Array
        (           
            [otherKey] => other value
            [secondLevel] => Array
                (           
                    [moreLevels] => Array
                        (           
                            [third] => third level
                            [thirdObj] => Array
                                (
                                    [fourth] => fourth level
                                )
                
                        )
        
                    [second] => second level
                )

        )

)

So all good as far as I can tell!

@LukeTowers LukeTowers merged commit a03fe11 into develop Aug 14, 2024
11 checks passed
@LukeTowers LukeTowers deleted the fix/snowboard-nested-request-data branch August 14, 2024 15:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants