When viewing an individual record, I'm using a calculated field from a sql query to display as a read only field in my form. However I'm unable to get it to display (no error, just blank). Curious, do I need a custom form to display this?
/forms/myform.xml
<field
name="current_age"
type="text"
readonly="true"
label="DOB_AGE"
description="DOB_AGE_DESC"
size="40"
default="0"
/>
fields/myfield.php
protected function getOptions()
{
$db = JFactory::getDBO();
$query = $db->getQuery(true);
$query->select('d.*,(YEAR(CURDATE())-YEAR(d.dancer_birthdate)) - (RIGHT(CURDATE(),5)<RIGHT(d.dancer_birthdate,5)) AS d.current_age,c.title as category');
$query->from('#__registration_dancers as d');
$query->leftJoin('#__categories as c on d.catid=c.id');
// Retrieve only published items
$query->where('d.published = 1');
$db->setQuery((string) $query);
$messages = $db->loadObjectList();
$options = array();
if ($messages)
{
foreach ($messages as $message)
{
$options[] = JHtml::_('select.option', $message->dancer_id, $message->dancer_name .
($message->catid ? ' (' . $message->category . ')' : ''), $message->dancer_birthdate,
$message->studio_id, $message->dateadded, $message->datemodified,
$message->current_age, $message->published);
}
}