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

Tweak: Enable [active_callback] For Repeater's Children #2498

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

HadyShaltout
Copy link

Version 4.1.1

Here's the solution of using [active_callback] array inside repeater controls to allow you show/hide other controls inside repeater's rows.

We've added the code in the unminified JS files until Kirki team decide to accept it and merge it to be able to minify via their minification tool.

The changes MUST be added to minfied version of js files:

File 1 - Unminified
.\kirki\kirki-packages\module-field-dependencies\src\control.js

File 1 - Minified
.\kirki\kirki-packages\module-field-dependencies\dist\control.js

File 2 - Unminified
.\kirki\kirki-packages\control-repeater\src\control.js

File 2 - Minified
.\kirki\kirki-packages\control-repeater\dist\control.js

Full Example:

new \Kirki\Field\Repeater( [

    'settings'     => '_builder_repeater',
    'label'       => esc_html__('Builder', 'text-domain'),
    'description' => '',
    'help'        => '',
    'section'     => 'section_id',
    'default'     => '',
    'priority'    => 10,

    'row_label' => array(
        'type'  => 'field',
        'value' => esc_html__('Layout', 'text-domain' ),
        'field' => 'layout',
    ),

    'default'     => array(),

    'fields' => array(
        'layout' => array(
            'type'        => 'select',
            'label'       => esc_html__( 'The Box Layout', 'text-domain' ),
            'description' => '',
            'default'     => 'classic',
            'choices'       => array(
                'horizontal'     => esc_html__( 'Horizontal', 'text-domain' ),
                'vertical'      => esc_html__( 'Vertical', 'text-domain' ),
                'review'       => esc_html__( 'Best Reviews', 'text-domain' ),
            )
        ),

        'title' => array(
            'type'        => 'text',
            'label'       => esc_html__( 'Title', 'text-domain' ),
            'description' => '',
            'default'     => '',
        ),

        'category' => array(
            'type'        => 'select',
            'label'       => esc_html__( 'Category', 'text-domain' ),
            'description' => '',
            'default'     => 'img',
            'choices'       => array(
                'img'   => esc_html__( 'Images', 'text-domain' ),
                'video'     => esc_html__( 'Video', 'text-domain' ),
                'audio'      => esc_html__( 'Audio', 'text-domain' ),
            ),
        ),

        'title_2' => array(
            'type'        => 'text',
            'label'       => esc_html__( 'Title #2', 'text-domain' ),
            'description' => '',
            'default'     => '',
            'active_callback'      => array(
                array(
                    'setting'  => 'layout',
                    'operator' => '==',
                    'value'    => 'vertical',
                ),
                array(
                    'setting'  => 'category',
                    'operator' => '==',
                    'value'    => 'video',
                )
            )
        ),
        'cat_2' => array(
            'type'        => 'select',
            'label'       => esc_html__( 'Category #2', 'text-domain' ),
            'description' => '',
            'default'     => 'animal',
            'choices'       => array(
                'animal'   => esc_html__( 'Animals', 'text-domain' ),
                'flys'     => esc_html__( 'Flys', 'text-domain' ),
            ),
            'active_callback'      => array(
                array(
                    'setting'  => 'layout',
                    'operator' => '==',
                    'value'    => 'vertical',
                )
            )
        ),


        'rev_title' => array(
            'type'        => 'text',
            'label'       => esc_html__( 'Review Title', 'text-domain' ),
            'description' => '',
            'default'     => '',
            'active_callback'      => array(
                array(
                    'setting'  => 'layout',
                    'operator' => '==',
                    'value'    => 'review',
                )
            )
        ),

    )

] );

Version 4.1.1

Here's the solution of using [active_callback] array inside repeater controls to allow you show/hide other controls inside repeater's rows.

We've added the code in the unminified JS files until Kirki team decide to accept it and merge it to be able to minify via their minification tool.

Because Kirki is using the minified js files you must minify the new code and (Only Append) to the [dist/control.js] files, DO NOT Replace the old ones.

File-1: .\kirki\kirki-packages\module-field-dependencies\src\control.js

Minify the new code before [jQuery(document).ready] and add it in
.\kirki\kirki-packages\module-field-dependencies\dist\control.js

Then append the line:

jQuery(document).ready((function(){KirkiRepeaterDependencies.init()}));

File-2: .\kirki\kirki-packages\control-repeater\src\control.js

We need to add the line
KirkiRepeaterDependencies.init();

in the minified version in [dist] directory:
.\kirki\kirki-packages\control-repeater\dist\control.js

Replace the old line
this.settingField.trigger("change")

With
(KirkiRepeaterDependencies.init(),this.settingField.trigger("change"))
Collect all repeater controls regardless it has [active_callback] or not to fix the issue appears while the parent repeater doesn't have an [active_callback] array
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant