简体   繁体   English

Joomla 2.5日历字段类型在自定义表单日期和时间选择中

[英]Joomla 2.5 calendar field type in custom form date and time selection

I have two fields in my admin/componsents/com_xxxxx/models/forms/xxxxx.xml file. 我的admin / componsents / com_xxxxx / models / forms / xxxxx.xml文件中有两个字段。

these feed into an input form for administrators on the back end of Joomla 2.5 这些为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" /> 

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. 但是,在选择日期选择器/日历图标并选择日期时,该字段将更新为所选日期,但保留09:30:00默认开始时间。 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. 这似乎适用于01:30:00到11:30之间的任何一个下午时间,当选择日期时,重置到现在。

can anyone explain why? 有谁能解释为什么? or how to keep the default times on the date selector? 或者如何在日期选择器上保留默认时间?

if the end date could also default to 28 days from the start date? 如果结束日期也可以默认为从开始日期起28天?

thanks in advance. 提前致谢。

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是一个无效的日期, Date.parseDate在功能上media/system/js/calendar-uncompressed.js试图猜测从格式字符串的所有组件的日期。 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 . 0000-00-00 09:30:00被认可为9月30日,因为09 < 12 ,所以它看起来像一个月号,因此它返回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 . 另一方面, 0000-00-00 19:30:00未被识别为任何有效日期,并且该函数today返回。 Hence the difference in the time part. 因此,时间部分的差异。

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. 例如,如果查看com_content的XML表单文件,您将看到它们不使用日历字段的默认值。

You could however create a custom field type derived from JFormFieldCalendar which would give you full flexibility. 但是,您可以创建从JFormFieldCalendar派生的自定义字段类型,这将为您提供充分的灵活性。 For example: 例如:

forms/whatever.xml 表格/ 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 田/ 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. 或者更适合您特定应用的任何东西。

Maybe this will be helpful for someone like me who was looking for answer on this question but on current version of Joomla 3.3.6: 也许这会对像我这样的人有所帮助,他们正在寻找这个问题的答案,但是对当前版本的Joomla 3.3.6:

<field
  name="birth_day"
  type="calendar"
  label="COM_PERSONS_PERSON_FIELD_BIRTHDAY_LABEL"
  description="COM_PERSONS_PERSON_FIELD_BIRTHDAY_DESC"
  class="inputbox" 
  size="20"
  format="%Y-%m-%d"
  filter="user_utc" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM