【问题标题】:Joomla 2.5 Custom Field List not SELECTED in displayJoomla 2.5 自定义字段列表未在显示中选择
【发布时间】:2012-09-08 12:40:10
【问题描述】:

我在我的组件“/models/fields/time.php”中使用以下 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>';
    }
}

和我的 course.xml (/models/forms/course.xml) 一样:

   <field 
   name="starttime" 
   type="time" 
       label="COM_CEXPRESS_FORM_LBL_COURSE_STARTTIME"
       description="COM_CEXPRESS_FORM_DESC_COURSE_STARTTIME" 
       required="true" 
       filter="safehtml" />

表单将在数据库中保存正确的值(09:30:00),但在显示表单时(上午 8:00)未选择正确的值=“已选择”。但是,如果我将 course.xml 字段修改为:

   <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>

表单将正确显示(上午 9:30)“选定”数据库值。我在此页面上使用了 Joomla 文档:

http://docs.joomla.org/Creating_a_custom_form_field_type

【问题讨论】:

  • 还有问题吗?如果是这样,请提供有关您的问题的更多内容。

标签: joomla joomla2.5


【解决方案1】:

您必须自己在 getInput() 中设置所选选项。您可以使用 $this->value 获取当前值。

您也可以通过 JHTML 来使用,而不是自己打印出元素:

public function getInput()
{
    $options = array(
        '08:00:00' => '8:00 AM',
        '09:30:00' => '9:30 AM'
    );

    return JHtml::_('select.genericlist', $options, $this->name, null, 'value', 'text', $this->value, $this->id);
}

【讨论】:

猜你喜欢
  • 2014-08-21
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-08-09
  • 1970-01-01
  • 1970-01-01
  • 2013-12-28
  • 1970-01-01
相关资源
最近更新 更多