Unyson icon indicating copy to clipboard operation
Unyson copied to clipboard

Built-in Option Type: Multi-Picker (Select)

Open themesmeta opened this issue 12 years ago • 5 comments

Hi there, I have a select box with 10 options ("option-1" will link with 3 textbox, rest of 9 options link with the same 2 textbox and 1 textarea. You know the problem is I have to define all of 10 options that let me use so many lines of code, and what's happened if I have a select box with more than 10 options ? Is there any solution to make this Option Type more flexible ?

themesmeta avatar Oct 25 '14 07:10 themesmeta

Maybe you can use only 2 options if 9 of 10 are the same?

Can you provide the option-type array so we can understand better why you need such functionality?

ghost avatar Oct 25 '14 08:10 ghost

Sure, here we go:

    'box_type_select' => array(
        'type'  => 'multi-picker',
        'label' => false,
        'desc'  => false,
        'picker' => array(
            'box_type' => array(
                'label'   => __('Select type', 'fw'),
                'type'    => 'select',
                'choices' => array(
                    '' => __( 'Default (no icon)', 'fw' ),
                    'box-1' => __( 'Box-1 title', 'fw' ),
                    'box-2' => __( 'Box-2 title', 'fw' ),
                    'box-3' => __( 'Box-3 title', 'fw' ),
                    'box-4' => __( 'Box-4 title', 'fw' ),
                    'box-5' => __( 'Box-5 title', 'fw' ),
                                        'box-6' => __( 'Box-6 title', 'fw' ),
                                        'box-7' => __( 'Box-7 title', 'fw' ),
                                        'box-8' => __( 'Box-8 title', 'fw' ),
                                        'box-9' => __( 'Box-9 title', 'fw' ),
                )
            )
        ),
        'choices' => array(
            'box-1' => array(
                'box_icon_anim' => array(
                    'type'  => 'select',
                    'label' => __('Choose an animation icon', 'fw'),
                    'choices' => array(
                        'fw-icon-macbook' => __('Animation icon Macbook', 'fw'),
                        'fw-icon-browser' => __('Animation icon Browser', 'fw'),
                        'fw-icon-clock' => __('Animation icon Clock', 'fw'),
                                                .....
                    )
                )
            ),
            'box-2' => array(
                'box_icon' => array(
                    'type'  => 'icon',
                    'label' => __('Choose an icon', 'fw'),
                )
            ),
            box-3' => array(
                'box_icon' => array(
                    'type'  => 'icon',
                    'label' => __('Choose an icon', 'fw'),
                )
            ),
            box-4' => array(
                'box_icon' => array(
                    'type'  => 'icon',
                    'label' => __('Choose an icon', 'fw'),
                )
            ),
            box-5' => array(
                'box_icon' => array(
                    'type'  => 'icon',
                    'label' => __('Choose an icon', 'fw'),
                )
            ),
            box-6' => array(
                'box_icon' => array(
                    'type'  => 'icon',
                    'label' => __('Choose an icon', 'fw'),
                )
            ),
            box-7' => array(
                'box_icon' => array(
                    'type'  => 'icon',
                    'label' => __('Choose an icon', 'fw'),
                )
            ),
            box-8' => array(
                'box_icon' => array(
                    'type'  => 'icon',
                    'label' => __('Choose an icon', 'fw'),
                )
            ),
            box-9' => array(
                'box_icon' => array(
                    'type'  => 'icon',
                    'label' => __('Choose an icon', 'fw'),
                )
            ),
        ),
        'show_borders' => false,
    ),

themesmeta avatar Oct 25 '14 08:10 themesmeta

I don't know how to solve this.

Maybe you have an idea how this can be done?

ghost avatar Oct 25 '14 09:10 ghost

Hey @moldcraft , I wish I can do something like this:

'box_icon' => array(
    'type'  => 'icon',
    'label' => __('Choose an icon', 'fw'),
    'dependencies' => array(
        'element' => 'box_type',
        'value' => array('box-2', 'box-3', 'box-4', 'box-5', 'box-6', 'box-7', 'box-8', 'box-9')
    )
)

Hope this makes sense. Anyway, you guys did a great work with this framework. Thanks so much !

themesmeta avatar Oct 25 '14 09:10 themesmeta

Hello @RayNguyen,

This is an interesting idea, for now you could store the repeating options into a variable and merge the multi-picker choices with it when you need to include them.

$price_option = array(
    'price' => array(
        'type'  => 'text',
        'label' => __('Price', 'fw'),
    )
);

$options = array(
    'demo' => array(
        'type'  => 'multi-picker',
        'label' => false,
        'desc'  => false,
        'picker' => array(
            'gadget' => array(
                'label'   => __('Test', 'fw'),
                'desc'    => __('Test', 'fw'),
                'type'    => 'select',
                'choices' => array(
                    'phone'  => __('Phone', 'fw'),
                    'laptop' => __('Laptop', 'fw')
                ),

            )
        ),
        'choices' => array(
            'phone' => array_merge(
                $price_option,
                array(
                    'memory' => array(
                        'type'  => 'select',
                        'label' => __('Memory', 'fw'),
                        'choices' => array(
                            '16' => __('16Gb', 'fw'),
                            '32' => __('32Gb', 'fw'),
                            '64' => __('64Gb', 'fw'),
                        )
                    )
                )
            ),
            'laptop' => array_merge(
                $price_option,
                array(
                    'webcam' => array(
                        'type'  => 'switch',
                        'label' => __('Webcam', 'fw'),
                    )
                )
            ),
        ),
        'show_borders' => false,
    ),
);

You will have to chose from generating the choices via code (like in the example above or some tricky foreach loop) or just stick with copy pasting the options for now.

Hope this helps and thank you for your contribution.

rockalife avatar Oct 27 '14 08:10 rockalife