Conditional logic with relationship field
-
Hi!
I’m trying to show a field in a CPT based on the value of another relationship field (which is linked to a custom taxonomy. I am using a relationship field rather than a taxonomy connection because it needs to be a single select).
The parameters for the conditional logic I’m using are:
- Show
- all
- relationship_name
- is (id/value)
I have tried the ID, the slug and the name, with and without quotation marks, but nothing seems to work as the field is never shown.
I’m using Pods 3.0.3
Thanks in advance
-
To confirm — the you were entering the
term_idyou want to filter by for the value, correct?I can confirm on my end that this is how it is working with the one I just tested myself.
That’s right, I’m using the
term_idof the taxonomy term:
I’m using single select and radio buttons as display options in the field used for filtering.
That exact usage works for my case on a CPT with a relationship field to a taxonomy.
The next step may be to try opening your browser console and set it to show verbose/debug logs. Then go to the screen with your field that should be showing. Clear the logs to ensure nothing else is showing up for our test here.
Then try changing the value to a different term and then back to that term with the ID 78. Take a look at the logs and perhaps provide what that says.
Here’s an example after I changed the value of my taxonomy test field to the term (ID: 88) which is what my conditional logic field is set to show on. Then right after that I switch to a different one.
pods-dfv.min.js?ver=0d4d9fb35b69e492260e:1 Conditional logic: enabled pods-dfv.min.js?ver=0d4d9fb35b69e492260e:1 {fieldName: 'test_field_copy', conditionalLogic: {…}, allPodValues: {…}} pods-dfv.min.js?ver=0d4d9fb35b69e492260e:1 Conditional logic: validateConditionalValue doesValueMatch pods-dfv.min.js?ver=0d4d9fb35b69e492260e:1 {fieldName: 'test_field_copy', fieldNameToTest: 'related_category_copy', doesValueMatch: true, compare: '=', ruleValue: '88', …} pods-dfv.min.js?ver=0d4d9fb35b69e492260e:1 Conditional logic: enabled pods-dfv.min.js?ver=0d4d9fb35b69e492260e:1 {fieldName: 'test_field_copy', conditionalLogic: {…}, allPodValues: {…}} pods-dfv.min.js?ver=0d4d9fb35b69e492260e:1 Conditional logic: validateConditionalValue doesValueMatch pods-dfv.min.js?ver=0d4d9fb35b69e492260e:1 {fieldName: 'test_field_copy', fieldNameToTest: 'related_category_copy', doesValueMatch: false, compare: '=', ruleValue: '88', …}You might want to “click” to expand some of those objects there for additional debug info that will copy/paste into this forum reply.
Here’s an example of them expanded for my reply:
pods-dfv.min.js?ver=0d4d9fb35b69e492260e:1 Conditional logic: enabled pods-dfv.min.js?ver=0d4d9fb35b69e492260e:1 {fieldName: 'test_field_copy', conditionalLogic: {…}, allPodValues: {…}}allPodValues: {publication_date: '1960-06-01', genre: 'political-philosophy', language: 'greek', country: 'GR', book_author: Array(1), …}conditionalLogic: {action: 'show', logic: 'any', rules: Array(1)}fieldName: "test_field_copy"Prototype: Object pods-dfv.min.js?ver=0d4d9fb35b69e492260e:1 Conditional logic: validateConditionalValue doesValueMatch pods-dfv.min.js?ver=0d4d9fb35b69e492260e:1 {fieldName: 'test_field_copy', fieldNameToTest: 'related_category_copy', doesValueMatch: true, compare: '=', ruleValue: '88', …}compare: "="doesValueMatch: truefieldName: "test_field_copy"fieldNameToTest: "related_category_copy"ruleValue: "88"valueToTest: "88"Prototype: Object pods-dfv.min.js?ver=0d4d9fb35b69e492260e:1 Conditional logic: enabled pods-dfv.min.js?ver=0d4d9fb35b69e492260e:1 {fieldName: 'test_field_copy', conditionalLogic: {…}, allPodValues: {…}}allPodValues: {publication_date: '1960-06-01', genre: 'political-philosophy', language: 'greek', country: 'GR', book_author: Array(1), …}conditionalLogic: {action: 'show', logic: 'any', rules: Array(1)}fieldName: "test_field_copy"Prototype: Object pods-dfv.min.js?ver=0d4d9fb35b69e492260e:1 Conditional logic: validateConditionalValue doesValueMatch pods-dfv.min.js?ver=0d4d9fb35b69e492260e:1 {fieldName: 'test_field_copy', fieldNameToTest: 'related_category_copy', doesValueMatch: false, compare: '=', ruleValue: '88', …}compare: "="doesValueMatch: falsefieldName: "test_field_copy"fieldNameToTest: "related_category_copy"ruleValue: "88"valueToTest: "89"Prototype: ObjectOkey, I think I see the error, but I’m not sure why it’s happening. Comparison operator is ‘>’ in the console, even though it’s supposed to be set to ‘is’ (‘=’).

When I choose another value, which is greater than 78, the field is displayed!

Can you go into your fields and select a different comparison option and then switch it back to “is (id/value)” there? Then save the field and go to the form to see what comparison it uses. I’m curious to see if there might be something going on there somehow.
That’s exactly what I just did! And it works now. Thank you.
Do you know what could be happening?
Edit: Okay, it works, but only when I change the value and then select it back. When it loads, the field still does not appear
-
This reply was modified 2 years, 8 months ago by
arturofez.
To clarify — you said it works when you change the value and set it back — is that in the form itself or when editing the Pod Field configuration?
I can confirm that there seems to be a separate issue here with initial load of the screen, I’m looking into that.
Yes, the issue occurs during the initial load when editing the CPT instances (post.php?post=1234&action=edit)
Fixed in Pods 3.0.5, no ETA on release but it may go out tomorrow unless I find other things to address.
I just installed Pods 3.0.5, and it works now! Thanks.
Some follow-up questions:
- When the field is required, I can’t hide it because it shows a required error upon saving even when it is hidden. Is this the expected behavior?
- Will it be possible to apply conditional logic to group of fields in a pod?
Perhaps for a new feature or enhancement? Should I open an issue on GitHub?
Thank you again, the conditional logic feature is fenomenal!
Required fields are not fully bypassed by conditional logic right now, they don’t really talk to each other at the moment in the code so that connection needs to be developed.
As for conditional logic per group, that requires rewriting our meta box usage and other implementations.
Both those things will take a bit of React work and we don’t have a dedicated React developer at the moment as they just got hired at PayPal 🥲
-
This reply was modified 2 years, 8 months ago by
The topic ‘Conditional logic with relationship field’ is closed to new replies.