1

I have a custom field called time which has the below coding.

jimport('joomla.form.formfield');
jimport('joomla.form.helper');
JFormHelper::loadFieldClass('list');

class JFormFieldTime extends JFormFieldList{

  protected $type = 'time';

  public function getOptions($id='') {
    //Do the process and return
    return $options;
  }
}

The above works perfect at back-end because I have XML forms for each views.

My question now is how to show the field in the front-end where I don't have XML forms because of custom designs.

I tried the below in my edit.php (front-end)

require_once JPATH_LIBRARIES.'/mylib/fields/time.php';
$timefield = JFormHelper::loadFieldType('time', false);
$timeslots=$timefield->getOptions();

The above code gives all the options. Is there a simple way to convert this to a select list box. I know the hard way is to loop through and form the select box. Just want to know is there any simpler way like JHTML::...

1

I found the solution as simple as below.

JHtml::_('behavior.formvalidation');
JHtml::_('formbehavior.chosen', 'select');

require_once JPATH_LIBRARIES.'/mylib/fields/time.php';

$timefield = JFormHelper::loadFieldType('time', false);
$timeslots=$timefield->getOptions();

echo JHtmlSelect::genericlist($timeslots, "note_start_time",null,'value','text',$start_time)

It works cool.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.