#1 June 5, 2019 11:15am

doon.mok
Member
Registered: May 6, 2015
Posts: 141

One to Many field - List Parser Function help

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

#2 June 5, 2019 11:41am

timbuckingham
Administrator
From: Baltimore, MD
Registered: April 2, 2012
Posts: 970

Re: One to Many field - List Parser Function help

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

#3 June 5, 2019 11:53am

doon.mok
Member
Registered: May 6, 2015
Posts: 141

Re: One to Many field - List Parser Function help

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

#4 July 23, 2019 2:25pm

doon.mok
Member
Registered: May 6, 2015
Posts: 141

Re: One to Many field - List Parser Function help

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

#5 July 23, 2019 4:28pm

timbuckingham
Administrator
From: Baltimore, MD
Registered: April 2, 2012
Posts: 970

Re: One to Many field - List Parser Function help

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

#6 July 31, 2019 12:36pm

doon.mok
Member
Registered: May 6, 2015
Posts: 141

Re: One to Many field - List Parser Function help

Thanks Tim, that worked!

Offline

Board footer

Powered by FluxBB

The Discussion Forum is not available on displays of this size.