Skip to content

Instantly share code, notes, and snippets.

@jmcelreavey
Last active March 22, 2019 09:36
Show Gist options
  • Save jmcelreavey/ea2cd710991d7d29d3a6f0d231eb0852 to your computer and use it in GitHub Desktop.
Save jmcelreavey/ea2cd710991d7d29d3a6f0d231eb0852 to your computer and use it in GitHub Desktop.
Attaching additional data to a dropdown

http://www.rhubarbphp.com/manual/module.leaf.commoncontrols/selection/attached-data#content

When setting the array values:

    [1, 'John', ['Forename' => 'John', 'Surname' => 'Smith', 'Age' => 23]],
    [2, 'Jane', ['Forename' => 'Jane', 'Surname' => 'Doe', 'Age' => 33]],
    [3, 'Clover', ['Forename' => 'Clover', 'Surname' => 'Daniels', 'Age' => 43]]
]);

Or you can override on the model:

{
    protected function getPublicPropertyList()
    {
        $list = parent::getPublicPropertyList();
        $list[] = 'FirstName';
        $list[] = 'Surname';

        return $list;
    }
}

Then to use it in the javascript:

if (items.length > 0){
    alert(items[0].data.FirstName);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment