Hi guys,
In every project i do i run into the same 'problem'. It's actually not a real problem, but maybe there is a solution for it that i didn't think of.
Suppose i create a field group (landing page fields) for a template (landing page template). In that template there is a FAQ section that can be shown or hidden by the admin. I set this up adding a checkbox with the name 'Show FAQ section'. The section consist of a title, a text and some FAQ posts that are added with a reference field. To this fields i add a condition that is ($(show-faq-section) eq 1) . So far so good.
Now, in another template (home page template) the FAQ section is always shown. In current situation i have to create new fields for this section, since the other ones have the condition.
A solution might be creating a new fieldgroup that contains the fields and make the fieldgroup as a whole conditional. However, that is not the solution i'm looking for since we can't easliy control the order of the metaboxes.
So my question is; is there a way of setting up the condition in a field that is showing the dependant field when the dependee field is not used AND that is showing the dependant field when dependee field is used (and contains the right value)?
Thanks a lot!
Marc
I think what you'd be looking at is an "if empty/if the value is" condition.
That should be possible, either on the entire Group level or single fields level, by setting the conditions to something like below
($(my_field) ne ) AND ($(my_field) eq my_value)
There is no other way to compare if a field is used and has a specific value.
Hi Beda,
thanks for the reply. I try setting it up like you explained, however i think i made a mistake since the field (FAQ section title, see screenshot) is not showing up at all with the newly added condition (see screenshot) that relates to the checkbox (see FAQ section, see screenshot).
Could you give me a direction?
This works fine here.
1. Set up a Checkbox (not checkboxes, single one!)
2. Set up another field that holds a condition (created with the GUI) that checks for "Is not empty" and "Is 1". The code generated is:
($(field) ne ) AND ($(field) eq 1)
It is maybe a problem with the code you entered, I suggest creating them with the GUI, or maybe it's a problem with another plugin/theme, or I completely miss some step in the replication of the issue.
Please let me know if you can fix it with the GUI, or by disabling other Plugins/Themes on a testing site, or if I altogether miss a step