You are not logged in.
I added a One to Many field type to a module and trying to use the List Parser Function to display a different title. I have the new title displaying if not selected but if I add an item and save and then go back. The selected item title is the original, not the title from the List Parser Function. I'm not sure what I need to do to show the new title after its been added?
I was referencing this example you had
function parseManyToMany($data,$type) {
$return_data = array();
// If $type is true, we're parsing the full list of values available for a user to tag
if ($type === true) {
foreach ($data as $id => $description) {
$return_data[$id] = strtoupper($description);
}
return $return_data;
// If $type is false, we're parsing the currently tagged values
} else {
// Let's leave it how it is.
return $data;
}
}
I thought if I put the description in the else, it displays the new description but it also has all of them in the added section.
Offline
Can you share your parser code? The else condition is the data that's currently tagged, so if you want that data to also have an altered title you can just get rid of the if condition altogether and parse $data and then return it, like this:
public static function testOTM($data, $type) {
foreach ($data as $id => $title) {
$data[$id] = strtoupper($title);
}
return $data;
}
Offline
Hey Tim,
I removed the if else but all the items are still in the selected section.
https://imgur.com/a/nSwv80J
$return_data = array();
// if not selected
// if ($type === true) {
foreach ($policies as $item) {
$category_name = "";
$category = json_decode($item["category"]);
if($category[0]) {
foreach ($categories as $each) {
if($each["id"] == $category[0]) {
$category_name = " (" . $each["name"] . ")";
break;
}
}
}
$return_data[$item["id"]] = $item["policy"] . $category_name;
}
return $return_data;
// } else {
//return $data;
// }
Offline
Tim,
I figured out my issue but was wondering if I can pass a variable through the List Parser Function field. I want to pass the id of the row editing in the module.
For example:
List Parser Function field: policy::getPolicy($rowId, $data, $type)
Is this possible?
Offline
Sorry about not replying! Sometimes the forum doesn't send me follow-up emails.
I believe you'll need to get it from $bigtree["commands"] so in your list parser function you'll need to run
global $bigtree;
and then $bigtree["commands"][0] will be the ID of the module entry being edited.
Offline
Thanks Tim, that worked!
Offline