laravel / prompts

Beautiful and user-friendly forms for your command-line PHP applications.
https://laravel.com/docs/prompts
MIT License
533 stars 94 forks source link

Discrepancy between `multiselect` return value and displayed value #52

Closed irobin591 closed 1 year ago

irobin591 commented 1 year ago

Laravel Prompts Version

0.1.5

Laravel Version

10.19.0

PHP Version

8.2.8 (in docker image)

Operating System & Version

macOS 13.5 (Intel) + Docker 4.18.0 + Dockerimage mcr.microsoft.com/devcontainers/php:1-8.2-bullseye

Terminal Application

VSCode Terminal

Description

When using multiselect prompts with arrays matching the array_is_list requirement, the selected options are displayed differently as they are returned.

Steps To Reproduce

  1. Create a new command with the following code:
    
    $selectedPermissions = multiselect(
    'Select permissions',
    [
        'create',
        'read',
        'write',
        'delete',
    ],
    [
        'read',
        'write',
    ]
    );

dump($selectedPermissions);

2. Select the default values (read + write)
3. Observe the discrepancy between the displayed selected permissions and the actual selected permissions:

┌ Select permissions ──────────────────────────────────────────┐ │ create │ │ read │ └──────────────────────────────────────────────────────────────┘

array:2 [ // app/Console/Commands/Bug.php:45 0 => "read" 1 => "write" ]



You can find a minimal example on a brand-new Laravel project here: https://github.com/irobin591/laravel-prompts-bug (see [app/Console/Commands/Bug.php](https://github.com/irobin591/laravel-prompts-bug/blob/main/app/Console/Commands/Bug.php))
jessarcher commented 1 year ago

Thanks @irobin591! I've created #53 to address this.