![](/img/trans.png)
[英]Joomla 2.5 calendar field type in custom form date and time selection
[英]Date format issues in Calendar form field type Joomla
我在Joomla Calendar form field
类型上遇到问题,这是我的代码:
<field name="date" type="calendar" label="Date (*)"
class="inputbox required" size="22"
format="%Y-%m-%d" labelclass="control-label" readonly="true" default="NOW"
/>
我想做的是在此字段中将默认值设置为当前日期,但它显示的是默认值,例如2014-03-07 00:00:00
但我不想在此字段中显示时间,因为您可以看到我定义了格式"%Y-%m-%d"
,但是不知道为什么如果有人对此有任何解决方案,它会像这样显示,请提供帮助。
尝试这个,
格式(可选)是要使用的日期格式。 这是PHP用于指定日期字符串格式的格式(请参见下文)。 如果未给出格式参数,则假定为'%Y-%m-%d'(给出的日期类似于“ 2008-04-16”)。
阅读更多
如果上述情况不起作用,请尝试以下方法。
在您的XML中
<field name="date" type="PubDateCalendar" label="Date (*)"
class="inputbox required" size="22"
format="%Y-%m-%d" labelclass="control-label" readonly="true"
/>
字段/pubdatecalendar.php
<?php
defined('_JEXEC') or die;
jimport('joomla.form.helper');
JFormHelper::loadFieldClass('calendar');
class JFormFieldPubDateCalendar extends JFormFieldCalendar
{
public $type = 'PubDateCalendar';
protected function getInput()
{
$this->value = date('Y-m-d');
return parent::getInput();
}
}
?>
希望它的作品..
改试试这个。。。这段代码和上面@Jobin Jose解决方案之间的区别是您调用父级。 在JFormFieldCalendar类中查看,它是具有自身格式的ovveride
<?php
defined('_JEXEC') or die;
jimport('joomla.form.helper');
JFormHelper::loadFieldClass('calendar');
class JFormFieldCustomCalendar extends JFormFieldCalendar
{
public $type = 'CustomCalendar';
protected $defaultFormat = 'd-m-Y';
/*
* Un jour d'intervalle entre le debut et la fin
*/
protected $interval = 'P1D';
protected function getInput()
{
parent::getInput();
// Build the attributes array.
$attributes = array();
empty($this->size) ? null : $attributes['size'] = $this->size;
empty($this->maxlength) ? null : $attributes['maxlength'] = $this->maxlength;
empty($this->class) ? null : $attributes['class'] = $this->class;
!$this->readonly ? null : $attributes['readonly'] = '';
!$this->disabled ? null : $attributes['disabled'] = '';
empty($this->onchange) ? null : $attributes['onchange'] = $this->onchange;
empty($hint) ? null : $attributes['placeholder'] = $hint;
$this->autocomplete ? null : $attributes['autocomplete'] = 'off';
!$this->autofocus ? null : $attributes['autofocus'] = '';
if ($this->required) {
$attributes['required'] = '';
$attributes['aria-required'] = 'true';
}
$date = new DateTime("now");
$format = $this->element['format'] ? (string) $this->element['format'] : $this->defaultFormat;
$validFormat = preg_replace('/%/', '', $format);
if ($this->element['default'] == 'start') {
$this->value = $date->format($validFormat);
} else if ($this->element['default'] == 'end') {
$date->add(new DateInterval($this->interval));
$this->value = $date->format($validFormat);
}
return JHtml::_('calendar', $this->value, $this->name, $this->id, $format, $attributes);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.