-
Notifications
You must be signed in to change notification settings - Fork 331
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
Checkbox style toggling doesn't work correctly in value_pattern situation #1778
Comments
Hi Aristath, |
@kodeoagency thank you for taking the time to format the code to make it easier to test, I really really really appreciate it! I can test things easier this way and have the time to reply to more people ❤️ This works in all cases: Kirki::add_config( 'my_config', array(
'capability' => 'edit_theme_options',
'option_type' => 'theme_mod',
) );
Kirki::add_section( 'my_section', array(
'title' => esc_attr__( 'My Section', 'textdomain' ),
) );
Kirki::add_field( 'my_config', [
'settings' => 'h1_italic',
'type' => 'checkbox',
'default' => 1,
'transport' => 'auto',
'output' => [
[
'element' => 'h1',
'property' => 'font-style',
'value_pattern' => 'italic',
'exclude' => [ false, 0, '0' ],
],
[
'element' => 'h1',
'property' => 'font-style',
'value_pattern' => 'normal',
'exclude' => [ true, 1, '1' ],
]
],
'section' => 'my_section',
] ); If you define what you want both on and off cases to do, then no matter what the default value is, it will work. |
Hi Aristath. Let me show you:
For us this is a huge Problem, because in our parent theme we have more than 500 controls and the default values will be loaded from different child themes config files, so that there is always a mixed situation. Is there a way to fix this? Should I open a new issue? |
extremely weird. |
I was able to replicate the issue, but only when all the below conditions were met:
So this is the only combination that I found was causing the issue: 'default' => false,
'transport' => 'auto',
'output' => array(
array(
'element' => 'h1',
'property' => 'font-style',
'value_pattern' => 'italic',
'exclude' => [ false, 0, '0' ],
),
array(
'element' => 'h1',
'property' => 'font-style',
'value_pattern' => 'normal',
'exclude' => [ true, 1, '1' ],
),
), This is probably caused by a bug in the class-kirki-modules-postmessage.php which will soon be refactored completely so I know it's not what you want to hear, but I'm not going to work on fixing it because the new implementation will fix it anyway. The current code in there is too chaotic to debug and tracking this down will take a lot of time. Workarounds until the refactor of the postMessage module is completed: Workaround 1: There's no reason to have exclude in both args, this would work too: 'default' => false,
'transport' => 'auto',
'output' => array(
array(
'element' => 'h1',
'property' => 'font-style',
'value_pattern' => 'normal',
),
array(
'element' => 'h1',
'property' => 'font-style',
'value_pattern' => 'italic',
'exclude' => [ false, 0, '0' ],
),
), Workaround 2: h1 { font-style: normal; } and then in the control only include what overrides the default: 'default' => false,
'transport' => 'auto',
'output' => array(
array(
'element' => 'h1',
'property' => 'font-style',
'value_pattern' => 'italic',
'exclude' => [ false, 0, '0' ],
),
), Workaround 3: Kirki::add_field( 'my_config', [
'settings' => 'h1_font_style',
'section' => 'my_section',
'type' => 'radio-buttonset',
'default' => 'normal',
'transport' => 'auto',
'output' => [
[
'element' => 'h1',
'property' => 'font-style',
],
],
'choices' => [
'normal' => esc_attr__( 'Normal', 'textdomain' ),
'italic' => esc_attr__( 'Italic', 'textdomain' ),
],
] ); I'm hoping I'll be able to complete the refactor soon. |
Hello. |
@kodeoagency I tagged you on the ticket here #1709 for the postMessage module refactor but someone reported they did not get notified from that so I'm also posting it here so you can check it out when you have some time to spare. 👍 |
Thank you very much. |
Depending on the combination of the default and exclude value, styling toggling with a checkbox (switch on/off) is working or not.
You can use this code to reproduce the problem.
To make the problem clearer:
The text was updated successfully, but these errors were encountered: