I have a custom field type in my components "/models/fields/time.php" with the following php:
defined('JPATH_BASE') or die; jimport('joomla.form.formfield'); class JFormFieldTime extends JFormField { protected $type = 'time'; public function getInput() { return '<select id="'.$this->id.'" name="'.$this->name.'">'. '<option value="08:00:00" > 8:00 AM</option>'. '<option value="09:30:00" > 9:30 AM</option>'. '</select>'; } }
and my .xml course (/models/forms/course.xml) as such:
<field name="starttime" type="time" label="COM_CEXPRESS_FORM_LBL_COURSE_STARTTIME" description="COM_CEXPRESS_FORM_DESC_COURSE_STARTTIME" required="true" filter="safehtml" />
The form will save the correct value in the database (09:30:00), but the correct value will not be selected = "selected" when the form is displayed (8:00 AM). However, if I change the course.xml field as follows:
<field name="starttime" type="list" label="COM_CEXPRESS_FORM_LBL_COURSE_STARTTIME" description="COM_CEXPRESS_FORM_DESC_COURSE_STARTTIME" required="true" filter="safehtml"> <option value="08:00:00" > 8:00 AM</option> <option value="09:30:00" > 9:30 AM</option> </field>
the form will correctly display (9:30 a.m.) the value of the "selected" database. I used Joomla Docs for this page:
http://docs.joomla.org/Creating_a_custom_form_field_type
source share