Skip to content

Support simple arrays for choices without numeric array indexes becoming the form input values #15

@simonrjones

Description

@simonrjones

When an array of values is passed to "choices" this turns into a numeric-indexed array, e.g.

'choices'  => [
    'Blue',
    'Green',
    'Yellow',
]

Would return 0 if Blue was chosen, 1 if Green was chosen, etc.

Ideally this would return Blue for blue, etc.

This requires removing the zero-indexing on a simple array passed to choices. Either as an option or the default.

Example:
app/Forms/SubmitCfviResourceForm.php

->add('types', ChoiceType::class, [
                'help' => '',
                'rules' => ['required'],
                'choices'  => [
                    'Worksheet/Activity' => 'Worksheet/Activity',
                    'Checklist' => 'Checklist',
                    'Lesson plans and Schemes of work' => 'Lesson plans and Schemes of work',
                    'Templates' => 'Templates',
                    'Handbook/information guide' => 'Handbook/information guide',
                    'Tracking documents' => 'Tracking documents',
                    'Case studies/personal stories' => 'Case studies/personal stories',
                    'Multimedia resources' => 'Multimedia resources',
                    'Networks/community/support' => 'Networks/community/support',
                    'Government documentation/resources' => 'Government documentation/resources',
                    'CFVI Training and Information' => 'CFVI Training and Information',
                    'Books' => 'Books',
                    'Guidance' => 'Guidance',
                    'External Link' => 'External Link',
                ],
                'expanded' => true, 'multiple' => true,

            ])

Ideally this would be:

->add('types', ChoiceType::class, [
                'help' => '',
                'rules' => ['required'],
                'choices'  => [
                    'Worksheet/Activity', 
                    'Checklist',
                    'Lesson plans and Schemes of work',
                    'Templates',
                    'Handbook/information guide',
                    'Tracking documents',
                    'Case studies/personal stories',
                    'Multimedia resources',
                    'Networks/community/support',
                    'Government documentation/resources',
                    'CFVI Training and Information',
                    'Books',
                    'Guidance',
                    'External Link',
                ],
                'expanded' => true, 'multiple' => true,

            ])

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions