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

Multi-select input shows selected options as a single array #11333

Closed
kailumworkhouse opened this issue Jan 9, 2025 · 8 comments · May be fixed by #11630
Closed

Multi-select input shows selected options as a single array #11333

kailumworkhouse opened this issue Jan 9, 2025 · 8 comments · May be fixed by #11630

Comments

@kailumworkhouse
Copy link

Bug description

Multi-select input shows multiple selected options as a single array, instead of as individual values.

image

image

How to reproduce

Create a multi select input
Select multiple values
Save
Refresh

Logs

No response

Environment

Environment
Application Name: Laravel
Laravel Version: 10.48.22
PHP Version: 8.2.15
Composer Version: 2.6.6
Environment: local
Debug Mode: ENABLED
URL: localhost
Maintenance Mode: OFF

Cache
Config: NOT CACHED
Events: NOT CACHED
Routes: NOT CACHED
Views: CACHED

Drivers
Broadcasting: log
Cache: redis
Database: mysql
Logs: stack / single
Mail: smtp
Queue: database
Scout: elastic
Session: file

Statamic
Addons: 9
Sites: 1
Stache Watcher: Enabled
Static Caching: Disabled
Version: 5.34.0 PRO

Statamic Eloquent Driver
Asset Containers: file
Assets: eloquent
Blueprints: file
Collection Trees: file
Collections: file
Entries: file
Forms: file
Global Sets: file
Global Variables: file
Navigation Trees: file
Navigations: file
Revisions: file
Sites: file
Taxonomies: file
Terms: file
Tokens: file

Installation

Fresh statamic/statamic site via CLI

Additional details

No response

@kailumworkhouse
Copy link
Author

PR #11332

@duncanmcclean
Copy link
Member

I can't seem to reproduce this... what does the field look like in your blueprint's YAML file?

@kailumworkhouse
Copy link
Author

The value returns a collection, so it doesn't seem to break it down.

-
    handle: listing_fallback_colours
    field:
      options:
        Aubergine: Aubergine
        Beige: Beige
        Biscuit: Biscuit
        Black: Black
        Beech: Beech
        Blue: Blue
        Blossom: Blossom
        Brown: Brown
        Charcoal: Charcoal
        Chocolate: Chocolate
        'Dark Grey': 'Dark Grey'
        Grey: Grey
        Other: Other
        Pink: Pink
        Honey: Honey
        Ivory: Ivory
        'Light Grey': 'Light Grey'
        Linen: Linen
        'Natural Timber': 'Natural Timber'
        Navy: Navy
        Olive: Olive
        Onyx: Onyx
        Rouge: Rouge
        Seafoam: Seafoam
        Seaspray: Seaspray
        Shadow: Shadow
        Silver: Silver
        Stone: Stone
        Tahini: Tahini
        Teal: Teal
        White: White
      taggable: true
      push_tags: true
      multiple: true
      clearable: true
      type: select
      display: 'Listing fallback colours'
      width: 50

@duncanmcclean
Copy link
Member

Thanks!

Strangely, I can't seem to reproduce the issue on my end. The items are showing up correctly (even after a page refresh):

CleanShot 2025-01-13 at 10 58 23

Are you able to reproduce the issue on a fresh Statamic site? 🤔

@kailumworkhouse
Copy link
Author

You can recreate the behaviour with the following:

  1. Create multi-select field as above
  2. Create computed field and add it to the collection via the AppServiceProvider
Statamic::booted(function () {
    Collection::computed('<collection>', 'listing_fallback_colours_collection', function ($entry, $value) {
        $arrayColours = collect($entry->listing_fallback_colours)->map->value->toArray();

        return collect($arrayColours);
    });
});
  1. Add colours via multi-select field
    image

@duncanmcclean
Copy link
Member

Your computed field needs to return an array, not a collection (it needs to return data in the same format it'd come back from a file).

In your case, if you're purely getting the value of that other field, you can use the ->get() method to get the "raw" value:

Statamic::booted(function () {
    Collection::computed('playground', 'listing_fallback_colours_collection', function ($entry, $value) {
        return $entry->get('listing_fallback_colours');
    });
});

@simonworkhouse
Copy link
Contributor

@duncanmcclean We have been using Runway and a recent update changed things so that collections are no longer cast to arrays when preparing models for the publish form. Since one of our models provides a collection of strings like the example above, the select field type no longer functions correctly.

@duncanmcclean
Copy link
Member

Can you open an issue on the Runway repo?

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