From c4e568900520ebcb9b2ae9096325b6d0b92ed456 Mon Sep 17 00:00:00 2001 From: Alex Pearson Date: Thu, 21 Dec 2023 15:08:49 -0500 Subject: [PATCH] Docs (README.md): update documentation for conditional logic Update documentation to include how to apply conditional logic to a field when it is inside of a sub-field. How to do this is no apparent to me in the documentation. There is a closed issue that explains it, but I believe this is a common enough use case to warrant being in the documentation. --- README.md | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/README.md b/README.md index 941a894..5cb4596 100644 --- a/README.md +++ b/README.md @@ -296,6 +296,49 @@ To reference a field in conditional logic when inside a nested sub field (for ex } ``` +To reference a field in conditional logic when the field you are referencing is inside a nested sub field (for example, in a group), the `fieldPath` must have the parent and child field. The `fieldPath` should look like this: +``` +fieldParent_fieldChild +``` +This is how ACF Field Group Composer builds keys under the hood. By setting `fieldPath` this way, you are directly referencing the key of the field you want. +For example: +```json +{ + "label": "Content Options", + "name": "contentOptions", + "type": "group", + "sub_fields": [ + { + "label": "Has Content", + "name": "hasContent", + "type": "true_false" + }, + ] +}, +{ + "label": "Content Group", + "name": "contentGroup", + "type": "group", + "sub_fields": [ + { + "label": "Content", + "name": "contentHtml", + "type": "wysiwyg", + "conditional_logic": [ + [ + { + "fieldPath": "contentOptions_hasContent", + "operator": "==", + "value": "1" + } + ] + ] + } + ] +} +``` +> Becuase keys are built using the snake case, naming your fields using snake case could lead to issues. If in this previous example hasContent was named has_content, there could be issues with constructing the keys. + ## API ### ACFComposer\ACFComposer (class)