Conditional Logic Switch/ Field group without updating the page
Support › MB Conditional Logic › Conditional Logic Switch/ Field group without updating the page
- This topic has 4 replies, 2 voices, and was last updated 5 months, 3 weeks ago by
Peter.
-
AuthorPosts
-
June 16, 2025 at 7:45 PM #48450
Oli Thompson
ParticipantHi there,
I just wondered how I could show/hide content based on an on/off switch field..
(without having to reload the page)I have tried adding this code to the WP Admin Footer area in WPCodebox...
(I don't really know what i'm missing)jQuery(function($) { setTimeout(function () { const $switch = $('input[name="is_framed"]'); const $framingOptions = $('.Framing-options'); function toggleFramingOptions() { const isChecked = $switch.prop('checked'); console.log('Switch is checked:', isChecked); // debug if (isChecked) { $framingOptions.show(); } else { $framingOptions.hide(); $framingOptions.find('input[type="checkbox"]').prop('checked', false); } } toggleFramingOptions(); // run once on load $switch.on('change', toggleFramingOptions); // run when changed }, 300); // slight delay (adjust if needed) });Would appreciate any help anyone can give..
OliJune 16, 2025 at 10:51 PM #48457Peter
ModeratorHello Oli,
Is the element
Framing-optionscreated by Meta Box plugin? If so, you can simply follow the documentation to show/hide the field based on the switch field
https://docs.metabox.io/extensions/meta-box-conditional-logic/#with-uiIf not, it is a custom element on the editing page, you can follow this one to use conditional logic outside of the field group
https://docs.metabox.io/extensions/meta-box-conditional-logic/#using-outside-field-groupsJune 17, 2025 at 4:27 AM #48458Oli Thompson
ParticipantYes the Framing-options is a field group.
The issue is that although condition logic rules work when I press "update", the desired outcome is that I would like the field group to be automatically shown/ hidden when the switch is activated (without pressing the "update" button).
For this particular usecase I am not sure where to look. I tried copying these pages into chatgbt and asking what to do but I can't figure out how to implement the jquery method "if applicable"...
June 17, 2025 at 4:48 AM #48459Oli Thompson
Participanthere is my structure..
Commission Type (cloneable group):
--> Type:
--> Switch (for framing options):Framing Options (cloneable group to be shown/ hidden by switch):
--> Frame:
--> Price:June 17, 2025 at 10:35 PM #48464Peter
ModeratorHello,
>> I would like the field group to be automatically shown/ hidden when the switch is activated
Yes, it should work like that because the Conditional Logic feature will show/hide the elements using JavaScript. Please share your site admin account by submitting this contact form https://metabox.io/contact/
I will take a look. -
AuthorPosts
- You must be logged in to reply to this topic.