outl1ne / nova-page-manager

Static page and region manager for Laravel Nova - designed for headless CMS's.
MIT License
178 stars 38 forks source link

Generate correct FormData key for nested fields that have complex field values #164

Closed marttinnotta closed 11 months ago

marttinnotta commented 1 year ago

This issue can be observed ex. when placing Multiselect field inside SimpleRepeatable. What happens is that Multiselect produces value that is typeof object. In this case page manager handles field a bit differently. Now when it's combined with simple repeatable that produces FormData type field names then the field names generated in the last step before sending them off to Nova are invalid.

Example

    public function fields(Request $request)
    {
        return [
            SimpleRepeatable::make('Categories', 'categories', [
                    Multiselect::make('Category', 'category')->options($options)->saveAsJSON()->max(1),
            ]),
        ];
    }

In case like this simple repeatable will generate following key name: categories[0][category] After page manager (current version) it will look like this: data[en][categories[0][category]][0] After PR changes it will look like this: data[en][categories][0][category][0]