aerni / statamic-livewire-forms

Supercharge your Statamic forms with Livewire
https://statamic.com/addons/aerni/livewire-forms
Other
28 stars 2 forks source link

Select field throws an error( Cannot access offset of type array on array ) #67

Closed Vuorenheimo closed 3 weeks ago

Vuorenheimo commented 3 weeks ago

Hello!

While using this extension, I noticed that when adding select field to form blueprint, I get mentioned error while rendering form in view.

Steps to Reproduce

  1. Create new form.
  2. Add new blueprint.
  3. Add select field to blueprint.
  4. Add form to view, with {{ livewire:form handle="{ form_name }" }}
  5. Error visible in rendering.

Possible Solution

I think error is caused in WithOptions trait where mapWithKeys callback returns an associative array and array of options is passed as key to array.

Context (Environment)

Happens on fresh install of Laravel 11.

"php": "^8.3",
"aerni/livewire-forms": "^9.3",
"laravel/framework": "^11.9",
"statamic/cms": "^5.22"

Anyway, thank you for this extension. Livewire for the win!

niemenmaa commented 3 weeks ago

This happens to me also (running Laravel 10, statamic 5, newest version of this package).

Fixed by changing the line to

return collect($options)
            ->mapWithKeys(fn ($value) => [$value['key'] => __($value['value']  ?? $value['key']) ])
            ->toArray();
aerni commented 3 weeks ago

Looks like this bug was introduced with https://github.com/statamic/cms/pull/10336 in Statamic v5.21.0. I'll release a fix shortly.