自定义表单日期和时间选择中的Joomla 2.5日历字段类型 [英] Joomla 2.5 calendar field type in custom form date and time selection

查看:102
本文介绍了自定义表单日期和时间选择中的Joomla 2.5日历字段类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的admin/componsents/com_xxxxx/models/forms/xxxxx.xml文件中有两个字段.

I have two fields in my admin/componsents/com_xxxxx/models/forms/xxxxx.xml file.

这些信息输入到Joomla 2.5后端的管理员输入表中

these feed into an input form for administrators on the back end of Joomla 2.5

<field name="f_start" type="calendar" class="inputbox" 
             required="true" 
             format="%Y-%m-%d %H:%M:%S"
             default="0000-00-00 09:30:00" 
             label="COM_xxxxx_F_START"
             description="COM_xxxxx_F_START_DESC" 
             filter="safehtml" /> 

<field name="f_end" type="calendar" class="inputbox"
             required="true" 
             format="%Y-%m-%d %H:%M:%S"
             default="0000-00-00 19:30:30" 
             label="COM_xxxxx_F_END"
             description="COM_xxxxx_F_END_DESC" 
             filter="safehtml" /> 

这些实质上是文章发布的开始和结束日期. 然而,选择日期选择器/日历图标并选择一个日期时 字段会更新为所选日期,但保留默认的开始时间09:30:00. 这似乎适用于01:30:00到11:30之间的时间,在选择日期后,任何下午的时间都会重置为现在.

These are essentially start and end dates of when an article is published. however when selecting the datepicker/calendar icon and choosing a date the field is updated to the date chosen but keeps the 09:30:00 default start time. this seems to work for times between 01:30:00 through to 11:30 any afternoon times get reset to now when a date is selected.

谁能解释为什么? 或如何在日期选择器上保留默认时间?

can anyone explain why? or how to keep the default times on the date selector?

是否还可以将结束日期默认为从开始日期起28天?

if the end date could also default to 28 days from the start date?

提前谢谢.

推荐答案

单击日历图标时,日历窗口小部件会尝试将其自身定位在相应文本字段中包含的日期上.由于0000-00-00是无效日期,因此media/system/js/calendar-uncompressed.js中的Date.parseDate函数尝试从格式字符串的所有组成部分中猜测日期. 0000-00-00 09:30:00被识别为Sep 30,因为09 < 12,所以它看起来像一个月数,因此它返回Sep 30, 9:30.另一方面,不能将0000-00-00 19:30:00识别为任何有效日期,并且该函数将返回today.因此,时间部分是不同的.

When clicking on the calendar icon, the calendar widget tries to position itself on the date contained in the corresponding text field. As 0000-00-00 is an invalid date, the Date.parseDate function in media/system/js/calendar-uncompressed.js tries to guess the date from all components of the format string. 0000-00-00 09:30:00 is recognized as Sep 30, because 09 < 12, so it looks like a month number, and thus it returns Sep 30, 9:30. On the other hand, 0000-00-00 19:30:00 is not recognized as any valid date, and the function returns today. Hence the difference in the time part.

例如,如果查看com_content的XML表单文件,您会发现它们没有为日历字段使用默认值.

If you look at the XML form files for com_content for example, you'll see that they don't use default values for the calendar fields.

但是,您可以创建一个派生自JFormFieldCalendar的自定义字段类型,这将为您提供充分的灵活性.例如:

You could however create a custom field type derived from JFormFieldCalendar which would give you full flexibility. For example:

forms/whatever.xml

forms/whatever.xml

<field name="f_start" type="PubDateCalendar"
       format="%Y-%m-%d %H:%M:%S" default="start" ... />
<field name="f_end" type="PubDateCalendar"
       format="%Y-%m-%d %H:%M:%S" default="end" ... />

fields/pubdatecalendar.php

fields/pubdatecalendar.php

<?php
defined('_JEXEC') or die;
jimport('joomla.form.helper');
JFormHelper::loadFieldClass('calendar');

class JFormFieldPubDateCalendar extends JFormFieldCalendar
{
    public $type = 'PubDateCalendar';
    protected function getInput()
    {
        $format = $this->element['format']
                ? (string) $this->element['format']
                : '%Y-%m-%d';
        if ($this->element['default'] == 'start') {
            $this->value = strftime($format);
        } else if ($this->element['default'] == 'end') {
            $this->value = strftime($format, time() + 28 * 24 * 60 * 60);
        }
        return parent::getInput();
    }
}
?>

或任何更适合您特定应用程序的东西.

or whatever suits your particular application better.

这篇关于自定义表单日期和时间选择中的Joomla 2.5日历字段类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆