michaeluno / admin-page-framework

Facilitates WordPress plugin and theme development.
http://admin-page-framework.michaeluno.jp/
Other
339 stars 71 forks source link

Feature request - Add select all / select none #153

Closed ghost closed 9 years ago

ghost commented 9 years ago

Is it possible to have a way to select all check-boxes in an array? I have some arrays that are quite long with check boxes, and would be handy for the end user select all options in the array if they like.

If this is not currently possible, would you mind adding this to the feature request please tag. It is not something that I must have right now, only something that would be nice to have as an option.

Note, the only time I have seen anything similar was in a plugin for editing roles with permissions that had many checkbox fields.

michaeluno commented 9 years ago

Do you mean a separate checkbox that selects all the listed checkboxes?

ghost commented 9 years ago

Correct. I have this scenario on my options panel at the moment using the other framework I have previously mentioned in other threads. Hoping you have something similar for this framework. Reason for all these questions is I am thinking to switch frameworks for the next project and use APF.

screenshot 2014-10-18 21 40 49

ghost commented 9 years ago

Some admin pages I can have up to 50 checkboxes for the end user to select. So you can understand why I am looking for this option.

michaeluno commented 9 years ago

I see. Currently it is not possible with the built-in functionality. I'll add it to my todo list.

If you are familiar with jQuery scripts and can write one for such functionality, it is quite simple to add your jQuery scripts in a particular field. For example in the field definition array pass the script output in the after_field/before_field argument.

           array(
                'field_id'      => 'checkbox_field',
                'title'         => __( 'Checkboxes', 'your-text-domain' ),
                'type'          => 'checkbox',
                'label'         => array(
                    // generated array elements 
                ),
                'after_field'   => "<script>//Embed your script here</script>",
            ),
michaeluno commented 9 years ago

Now this is included in v3.3.0b. Download.

Set the button text in the select_none_button and select_all_button arguments. To use the system default text, just pass true.

    array( 
        'field_id'      => 'checkbox_repeatable_fields',
        'title'         => __( 'Repeatable', 'admin-page-framework-demo' ),
        'type'          => 'checkbox',
        'label'         => array( 'x', 'y', 'z' ),
        'repeatable'    =>    true,
        'select_all_button'     => __( 'Check All', 'admin-page-framework-demo' ),        // 3.3.0+   to change the label, set the label here
        'select_none_button'    => __( 'Uncheck All', 'admin=page-framework-demo' ),      // 3.3.0+   to change the label, set the label here                        
    ),
ghost commented 9 years ago

Michael, you are blazingly fast with these updates. Quite incredible. I think another beer is on the house for Friday afternoon.