<![CDATA[ Use MIGX TV as input for checkbox TV - My Forums]]> https://forums.modx.com/thread/?thread=71426 <![CDATA[Re: Use MIGX TV as input for checkbox TV]]> https://forums.modx.com/thread/71426/use-migx-tv-as-input-for-checkbox-tv#dis-post-475880
"Flexible" TVs are a great tool. I did this in the past with a "fake" resources.

@SELECT pagetitle, id FROM [+add_prefix+]site_content WHERE parent=[+add_parentid] ORDER BY menuindex

[+add_prefix+]. The modx table prefix (usually: modx_).
[+add_parentid+]. The id of the parent resource. ITs children will be available options in the TV. The value will be equals to the id of the selected child resource.

A more complex example can be found at the forum: http://forums.modx.com/index.php?topic=30102.0

Thanks your your contribution!

pepebe]]>
pepebe Aug 26, 2013, 08:53 AM https://forums.modx.com/thread/71426/use-migx-tv-as-input-for-checkbox-tv#dis-post-475880
<![CDATA[Re: Use MIGX TV as input for checkbox TV]]> https://forums.modx.com/thread/71426/use-migx-tv-as-input-for-checkbox-tv#dis-post-399530
<?php
$resource = $modx->getObject('modResource',1);
$migxEntries = $resource->getTVValue('tagOptions');
$migxEntries2 = json_decode($migxEntries, true);
$numItems = count($migxEntries2);
$i = 0;
foreach ($migxEntries2 as $key => $jsons) { // This will search in the 2 jsons
     foreach($jsons as $key => $value) {
        if($i+1 == $numItems) {
        	$output .= $value."==".$value; 
	} else {
	  $output .= $value."==".$value."||";
	}
       
        $i++;              
    }
}


return $output;
]]>
michelle84 Nov 10, 2011, 11:22 AM https://forums.modx.com/thread/71426/use-migx-tv-as-input-for-checkbox-tv#dis-post-399530
<![CDATA[Use MIGX TV as input for checkbox TV]]> https://forums.modx.com/thread/71426/use-migx-tv-as-input-for-checkbox-tv#dis-post-398553
I did this as follows (probably not the best way, I'm not a programmer):

1) created the admin-input tv named categoryInputOptions:
input type: migx
Form type:
[{
  "caption":"Categories",
  "fields": [{
    "field":"category",
    "caption":"Category"
  }]
}]

Grid columns:
[
{"header": "Category", "width": "30", "sortable": "false", "dataIndex": "category"}
]


2) Created the category tv named category:

input type: checkbox
input option values:
@EVAL return $modx->runSnippet('readCategoryOptions');


3) Created the snippet to display the category options from the first TV named readCategoryOptions:
<?php
$resource = $modx->getObject('modResource',1);

$migxEntries = $resource->getTVValue('categoryInputOptions');
$migxEntries2 = json_decode($migxEntries);


This is where I get stuck. The TV categoryInputOptions is managed on the resource with id 1. So I first get that resource and then I get the value of the TV categoryInputOptions on that resource. I understand this is a JSON string, so I try to decode it. This gives me an array.

My question is: how do I turn that array ($migxEntries2) into a string that can be used by TV category? I think it should be a string in the form value1||value2||value3.

I tried everything I could find on arrays, like implode, but nothing seems to work. Probably something small.. Anyone got a hint for me?]]>
michelle84 Oct 31, 2011, 08:12 AM https://forums.modx.com/thread/71426/use-migx-tv-as-input-for-checkbox-tv#dis-post-398553