MIGX listbox-multiple TV type not working

I have a listbox (multiple) inside a MIGX tv I put together. But I’m having trouble with the output. I have a need for a dropdown of all attorneys in our database so I can output specific items from their bios.

To do this, I used this for my InputOptionValues in my TV:

“inputOptionValues”:“@SELECT pagetitle, attorney.id AS id, tlastnamevalue.value AS lastname FROM modx_site_content attorney LEFT JOIN modx_site_tmplvar_contentvalues tlastnamevalue ON tlastnamevalue.contentid = attorney.id AND tlastnamevalue.tmplvarid = 10 WHERE published = 1 AND deleted = 0 AND (parent = 1 OR parent = 2 OR parent = 3 ) ORDER BY pagetitle ASC”

This got me my list, but when I use it, all I’m getting as a result is the resource ID (which is expected). However, what isn’t expected is that when I select multiple items, it combines the resource IDs rather than showing a delimiter.

Instead of 22,23 or 22||23, I’m getting 2223.

Any ideas on how to fix this? I tried searching for this and only found an unanswered article I posted from 2 years ago. >_<

How exactly do you get these ids without a separator? When you read the data?
If yes, how do you read the data?

If you look at the data in the database table modx_site_tmplvar_contentvalues, are the ids there correctly stored as an array?

Yes, it’s when i’m reading the data. Here’s my full process if this helps. The testing page.

The full TV:

[
  {"caption":"Info", "fields":
   [
      {"field":"GroupName","caption":"Name of the Group","inputTVtype":"text"},
      {"field":"Logo","caption":"Group Logo","inputTVtype":"image"},
      {"field":"GroupDescription","caption":"Description","inputTVtype":"richtext"}
   ]
  },
  {"caption":"People","fields":
   [
    { "field":"GroupChair",
      "caption":"Chairperson",
      "inputTVtype":"listbox-multiple",
      "inputOptionValues":"@SELECT `pagetitle`, attorney.id AS `id`, `tlastnamevalue`.`value` AS `lastname` FROM `modx_site_content` `attorney` LEFT JOIN modx_site_tmplvar_contentvalues tlastnamevalue ON tlastnamevalue.contentid = attorney.id AND tlastnamevalue.tmplvarid = 69 WHERE `published` = 1 AND `deleted` = 0 AND (`parent` = 1 OR `parent` = 2 OR `parent` = 3) ORDER BY `pagetitle` ASC",
      "config":{"typeAhead":false,"typeAheadDelay":250,"minChars":3}
    }
   ]
  }
]

The frontend:

[[getImageList?
    &tvname=`diversityAffinityGroupsList`
    &tpl=`affinityGroupsTpl2`
]]

The Chunk:

<p>[[+GroupName]]</p>
<p>[[+Logo]]</p>
<p>[[+GroupDescription]]</p>
<h1>[[#[[+GroupChair]].pagetitle]]</h1>

so in this example, I’m looking at the [[+GroupChair]] line and for the entry with more than one person, the resource IDs are combining. When I rename the chunk tpl and view the array in full, I get this:

Array
(
    [MIGX_id] => 2
    [GroupName] => Buchanan N.O.W.
    [Logo] => assets/images/Logos/diversity-NOW.jpg
    [GroupDescription] => 
Buchanan N.O.W (Network of Women) is the affinity group for employees who identify as women.


    [GroupChair] => 649225
    [GroupMembers] => 
    [_alt] => 1
    [_first] => 
    [_last] => 
    [idx] => 2
    [property.tvname] => diversityAffinityGroupsList
    [property.tpl] => affinityGroupsTpl2
)

The GroupChair should be 649,225

The problem seems to happen here in the code of the snippet “getimagelist”:

The value should be correct if you use the option &processTVs=`0` in your snippet call.

[[getImageList?
    &tvname=`diversityAffinityGroupsList`
    &tpl=`affinityGroupsTpl2`
	&processTVs=`0`
]]

If you need the other values to be processed, then you probably have to change the snippet and code an exception for this field.

Cool, that added a double pipe divider! But I’m confused on how i can use that now.

You probably have to write a custom snippet. Something like this:

Chunk affinityGroupsTpl2

<p>[[+GroupName]]</p>
<p>[[+Logo]]</p>
<p>[[+GroupDescription]]</p>
<h1>[[mySnippet? &ids=`[[+GroupChair]]`]]</h1>

Snippet mySnippet

<?php
$ids = $modx->getOption('ids',$scriptProperties,'');
$ids_array = array_map('trim', explode('||', $ids));

$output = array();
foreach ($ids_array as $id) {
    $resource = $modx->getObject('modResource', $id);
    if ($resource) {
        $output[] = $resource->get('pagetitle');
    }
}
return implode(", ", $output);