When using conditional display for a Post Field Group, if a field is set to conditionally NOT display by default, and the post is published, the fields no longer have a default value.
For example if I were to use an "enable table of contents" checkbox that is disabled by default, that when checked, shows a group of configuration settings that have default values: If the enable table of contents checkbox is checked before the post is published, when the conditional fields are displayed they properly have their default values. However, if the checkbox remains unchecked and the post is published, then I were to edit the post and check the "enable table of contents" checkbox, when the configuration fields are conditionally displayed, they will not have any default values, they are all just blank.
What I would like to have happen is the conditional fields retain their default whether they are shown when the post is saved or not
Uploading a subset of the group field settings for your convenience (the full field settings was too large of a file).
As you can see, "Use build Boc Toc Widget (or default settings) is conditionally displayed if "Enable Table of Contents" is checked. If "Use Boc Toc Widget (or default settings)" is not being displayed due to "Enable Table of Contents" not being checked when the post is saved, then when coming back to edit the post and checking "Enable Table of Contents", "use Boc Toc Widget will be conditionally displayed WITHOUT it's default value of checked.
Sorry for the confusing logic I hope this makes sense
Hello. Thank you for contacting the Toolset support.
You want that the default checkbox value for field "toc_default" should be saved as 'on' when you publish the post without checking the checkbox "toc" - correct? If yes, you can use the "save_post" hook for such custom logic and save the default value for your field.
Thanks for your help. This would work well if I knew for sure that the post would need to be saved with the default values. The issue in this case is that Since the configuration fields are conditionally displayed, The user could also change those values. I don't necessarily want to force a value, but I do want to set a default value that saves even if the field is not conditionally displayed.
So using the above example, if the user does not check "Enable Table of Contents" I want the default value of the hidden "Use build Boc Toc Widget (or default settings)" But if the user does check "Enable Table of Contents" and now "Use build Boc Toc Widget (or default settings)" is conditionally displayed, I don't want to override the value the user chose
Then you will have to adjust the code conditionally to check if the selection is made or not.
if you do not know how to do it, please share problem URL and what selection I have to made and admin access details so I can adjust the code.
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I have set the next reply to private which means only you and I have access to it.
Thanks for all the help. I'll play around with it. I can probably write the code but I was hoping that setting a default for a hidden field would be possible, to handle it within toolset config only. Is it intended functionality that a hidden field cannot have a default value? Is it possible this is a bug?
It not the bug as you are wrapping the field with conditional and hence the field is hidden based on conditional it will not hold the value. If it will hold the value then its against the condition that field should remain hidden. So, what you see if expected behavior and we have a way to workaround it.