I have found that implementing a custom field (extending JFormFieldList) is a good way to achieve this. Consider the following custom field code:
// No direct access to this file
defined('_JEXEC') or die;
// import the list field type
jimport('joomla.form.helper');
JFormHelper::loadFieldClass('list');
class JFormFieldMylist extends JFormFieldList
{
/**
* The field type.
*
* @var string
*/
protected $type = 'mylist';
/**
* Method to get a list of options for a list input.
*
* @return array An array of JHtml options.
*/
protected function getOptions()
{
JLoader::register('myhelper', JPATH_ROOT . '/path/to/myhelper/helper.php');
$helper = new myhelper();
$results = $helper->get_list();
$options = array();
if ($results){
foreach($results as $result) {
$options[] = JHtml::_('select.option', $result->id, $result->name);
}
}
$options = array_merge(parent::getOptions(), $options);
return $options;