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

active_callback operator using '<=' or '>=' #1427

Closed
designaction-ria opened this issue Jun 25, 2017 · 7 comments
Closed

active_callback operator using '<=' or '>=' #1427

designaction-ria opened this issue Jun 25, 2017 · 7 comments
Milestone

Comments

@designaction-ria
Copy link

Issue description:

The latest Kirki update seems to have switched the operator logic for greater than/less than or equal to.

I have a number slider (from 1 through 7) that controls the visibility of other fields. For example, if the number slider is set to 3, field_1, field_2, and field_3 would show, but field_4 through field_7 would be hidden. (Field names are just to illustrate/simplify).

Up until the latest update, this has worked perfectly using the <= operator on each field, and checking the number slider value within the active_callback. However, with the latest release, I had to switch to the >= operator to get it to work—in essence, the logic has switched.

There also appears to be different logic used during the page refresh—if I have the operator set to <= and I change the number slider, I'll see the correct logic during the page refresh, but once the refresh is complete it will switch to using the incorrect logic.

Version used:

3.0.4

Using theme_mods or options?

theme_mod

Code to reproduce the issue (config + field(s))

Example number slider (setting number of slides to show):

Kirki::add_field( 'NAMESPACE', array(
	'type'        => 'slider',
	'settings'    => 'NAMESPACE_slides_slide_number',
	'label'       => esc_attr__( 'Number of slides', 'NAMESPACE' ),
	'section'     => 'NAMESPACE_slides',
	'default'     => 1,
	'choices'     => array(
		'min'  => 1,
		'max'  => 7,
		'step' => 1,
	),
) );

Example field, using the <= operator that is no longer working correctly in the latest update:

Kirki::add_field( 'NAMESPACE', array(
	'settings' => 'NAMESPACE_slides_slide_2',
	'label'    => __( 'Slide 2', 'NAMESPACE' ),
	'section'  => 'NAMESPACE_slides',
	'type'     => 'editor',
	'priority' => 30,
	'default'  => '',
	'active_callback'    => array(
		array(
			'setting'  => 'NAMESPACE_slides_slide_number',
			'operator' => '<=',
			'value'    => 2,
		),
	),
) );
@aristath aristath modified the milestones: 3.0.5, 3.0.6, 3.0.7 Jun 25, 2017
@aristath
Copy link
Contributor

aristath commented Jun 27, 2017

I just tested your code and it looks to me like it's working perfectly fine.
The full code I used:

Kirki::add_config( '_s' );
Kirki::add_section( 'theme_options', array(
	'title' => esc_attr__( 'Theme Options', '_s' ),
	'icon'  => 'dashicons-admin-customizer',
));
Kirki::add_field( '_s', array(
	'type'        => 'slider',
	'settings'    => '_s_slides_slide_number',
	'label'       => esc_attr__( 'Number of slides', '_s' ),
	'section'     => 'theme_options',
	'default'     => 1,
	'choices'     => array(
		'min'  => 1,
		'max'  => 7,
		'step' => 1,
	),
) );
Kirki::add_field( '_s', array(
	'settings' => '_s_slides_slide_2',
	'label'    => __( 'Slide 2', '_s' ),
	'section'  => 'theme_options',
	'type'     => 'editor',
	'priority' => 30,
	'default'  => '',
	'active_callback'    => array(
		array(
			'setting'  => '_s_slides_slide_number',
			'operator' => '<=',
			'value'    => 2,
		),
	),
) );

When _s_slides_slide_number is 1 or 2, _s_slides_slide_2 is shown.
When _s_slides_slide_number is anything above 2, _s_slides_slide_2 is hidden.
A rough translation of the condition you've got there in active_callback would be this:

if ( get_theme_mod( '_s_slides_slide_number' ) <= 2 ) {
      // SHOW CONTROL
} else {
    // HIDE CONTROL
}

@designaction-ria
Copy link
Author

Thanks for looking into this! Unfortunately I'm still seeing the issue on my end—let me see if I can do a better job explaining what's going on.

The issue seems to kick in once there are three or more sections (not just two). See this GIF (and watch the slide numbers change):
active_callback

You'll see there are a number of slide fields—changing the number slider changes what number of Slide editors are available for updating.

You can see that when I drag the slider, the conditional fields immediately shift—once the screen finishes refreshing, the available fields again change. The during-refresh and after-refresh states seem to follow the opposite logic—when I use >=, fields show correctly after the page refresh but incorrectly while loading, and the opposite occurs when using <=. Prior to this recent update, both were in sync—ie., I'd move the slider, the correct fields would show while waiting for the page refresh, then the correct fields would still show (no change). After the recent update, they now behave with opposite logic.

@aristath
Copy link
Contributor

aristath commented Jun 27, 2017

Can you please post the code for ALL those fields so that I may replicate this? In your previous reply you only included 1.

@designaction-ria
Copy link
Author

Sure, here's a simplified version based on your example:

Kirki::add_config( '_s' );
Kirki::add_section( 'theme_options', array(
	'title' => esc_attr__( 'Theme Options', '_s' ),
	'icon'  => 'dashicons-admin-customizer',
));
Kirki::add_field( '_s', array(
	'type'        => 'slider',
	'settings'    => '_s_slides_slide_number',
	'label'       => esc_attr__( 'Number of slides', '_s' ),
	'section'     => 'theme_options',
	'default'     => 1,
	'choices'     => array(
		'min'  => 1,
		'max'  => 5,
		'step' => 1,
	),
) );
Kirki::add_field( '_s', array(
	'settings' => '_s_slides_slide_1',
	'label'    => __( 'Slide 1', '_s' ),
	'section'  => 'theme_options',
	'type'     => 'editor',
	'priority' => 10,
	'default'  => '',
	'active_callback'    => array(
		array(
			'setting'  => '_s_slides_slide_number',
			'operator' => '>=',
			'value'    => 1,
		),
	),
) );
Kirki::add_field( '_s', array(
	'settings' => '_s_slides_slide_2',
	'label'    => __( 'Slide 2', '_s' ),
	'section'  => 'theme_options',
	'type'     => 'editor',
	'priority' => 20,
	'default'  => '',
	'active_callback'    => array(
		array(
			'setting'  => '_s_slides_slide_number',
			'operator' => '>=',
			'value'    => 2,
		),
	),
) );
Kirki::add_field( '_s', array(
	'settings' => '_s_slides_slide_3',
	'label'    => __( 'Slide 3', '_s' ),
	'section'  => 'theme_options',
	'type'     => 'editor',
	'priority' => 30,
	'default'  => '',
	'active_callback'    => array(
		array(
			'setting'  => '_s_slides_slide_number',
			'operator' => '>=',
			'value'    => 3,
		),
	),
) );
Kirki::add_field( '_s', array(
	'settings' => '_s_slides_slide_4',
	'label'    => __( 'Slide 4', '_s' ),
	'section'  => 'theme_options',
	'type'     => 'editor',
	'priority' => 40,
	'default'  => '',
	'active_callback'    => array(
		array(
			'setting'  => '_s_slides_slide_number',
			'operator' => '>=',
			'value'    => 4,
		),
	),
) );
Kirki::add_field( '_s', array(
	'settings' => '_s_slides_slide_5',
	'label'    => __( 'Slide 5', '_s' ),
	'section'  => 'theme_options',
	'type'     => 'editor',
	'priority' => 50,
	'default'  => '',
	'active_callback'    => array(
		array(
			'setting'  => '_s_slides_slide_number',
			'operator' => '>=',
			'value'    => 5,
		),
	),
) );

@aristath
Copy link
Contributor

OK, I see the problem now.

aristath added a commit that referenced this issue Jun 27, 2017
@aristath
Copy link
Contributor

Fixed, will be included in 3.0.8.

aristath added a commit that referenced this issue Jun 27, 2017
@designaction-ria
Copy link
Author

Great, thank you so much!

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

No branches or pull requests

2 participants