Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected behavior with ACT pod relationship field value array #2513

Closed
chilledfresh opened this issue Dec 11, 2014 · 2 comments
Closed

Unexpected behavior with ACT pod relationship field value array #2513

chilledfresh opened this issue Dec 11, 2014 · 2 comments
Assignees
Milestone

Comments

@chilledfresh
Copy link

I have two CPT pods, Pod A and Pod B. Pod A has a multi-select relationship field (checkboxes) pointing to Pod B. Pod B has three records. I set up a pre-save filter for Pod A using pods_api_pre_save_pod_item, which simply determines if anything has been checked in Pod A's form:

if ( $pieces['fields']['pod_b']['value'] == '' )

If no checkboxes are selected in Pod A's form, the if statement returns true.

I duplicated this setup, this time using ACT pods. The if statement returns false. Here's the pre-save var_dump output of the $pieces['fields']['pod_b']['value'] array:

Custom Post Type: nothing checked
array(3) { [0]=> int(122) [1]=> int(123) [2]=> int(124) }

Custom Post Type: all options checked
array(3) { [0]=> string(3) "122" [1]=> string(3) "123" [2]=> string(3) "124" }

Custom Post Type: second and third option checked
array(2) { [1]=> string(3) "123" [2]=> string(3) "124" }

Advanced Content Type: nothing checked
array(1) { [0]=> string(1) "0" }

Advanced Content Type: all options checked
array(3) { [0]=> string(1) "1" [1]=> string(1) "2" [2]=> string(1) "3" }

Advanced Content Type: second and third option checked
array(3) { [0]=> string(1) "0" [1]=> string(1) "2" [2]=> string(1) "3" }

Advanced Content Type: third option checked
array(2) { [0]=> string(1) "0" [2]=> string(1) "3" }

As you can see, while the CPT pod returns an array with only keys, the ACT pod's array also contains a value ("0"). This makes validating $pieces['fields']['pod_b']['value'] more complicated, since the array has a value even when no checkboxes are selected.

Also, notice how the ACT pod adds a "0" record to the array whenever the first option is unchecked, resulting in an unexpected number of rows.

@chilledfresh chilledfresh changed the title Strange behavior with ACT pod relationship field value array Unexpected behavior with ACT pod relationship field value array Dec 11, 2014
jamesgol added a commit that referenced this issue Dec 11, 2014
@jamesgol
Copy link
Contributor

That should fix the issue. This doesn't happen if the format is 'Checkboxes' or 'Autocomplete'. On a CPT there is no data being passed in the POST for that field, in an ACT the field is being passed as empty '' which pods is translating to an empty item. Which is legit behavior on the pods side.

I suspect that the WordPress post side is unsetting empty values so it doesn't pass them along, but I didn't trace all the js code to see where it is happening

@jamesgol
Copy link
Contributor

Same as #1862, though this did lead me to discover another bug that the PR I submitted fixes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants