#6079: Form Helper - DateTime: Providing a YmD for short month
-------------------------------+--------------------------------------------
Reporter: justinvh | Type: Enhancement
Status: new | Priority: Medium
Milestone: 1.2.x.x | Component: Helpers
Version: 1.2 Final | Severity: Trivial
Keywords: DateTime, Form | Php_version: PHP 5
Cake_version: 1.2.1.8004 |
-------------------------------+--------------------------------------------
== Situation ==
As of 1.2.1.8004 Stable DateTime provides a way to auto-generate all forms
YYYY-MM-DD and YYYY-LONGMONTH-DD, however there is no way to produce a
short-month form without modifying the form helper.
== Possible Implementation ==
'''In the form helper:'''[[BR]]
Provided another case of 'shortMonth' to generationOptions:
{{{
#!php
function __generateOptions($name, $options = array()) {
...
case 'shortMonth':
if ($options['monthNames']) {
$data['01'] = __('Jan', true);
$data['02'] = __('Feb', true);
$data['03'] = __('Mar', true);
$data['04'] = __('Apr', true);
$data['05'] = __('May', true);
$data['06'] = __('Jun', true);
$data['07'] = __('Jul', true);
$data['08'] = __('Aug', true);
$data['09'] = __('Sep', true);
$data['10'] = __('Oct', true);
$data['11'] = __('Nov', true);
$data['12'] = __('Dec', true);
} else {
for ($m = 1; $m <= 12; $m++) {
$data[sprintf("%02s", $m)] = strftime("%m", mktime(1, 1, 1, $m, 1,
1999));
}
}
break;
...
}
}}}
In the function month, provide an optional argument $useShort and a
conditional for generating the month list:
{{{
#!php
function month($fieldName, $selected = null, $attributes = array(),
$showEmpty = true, $useShort = false) {
...
return $this->select(
$fieldName . ".month",
$this->__generateOptions((($useShort == true) ? 'shortMonth' :
'month'), array('monthNames' => $monthNames)),
$selected, $attributes, $showEmpty
);
}
}}}
And finally, in the function DateTime, add another case to the preg_split
on dateFormat:
{{{
#!php
function dateTime($fieldName, $dateFormat = 'DMY', $timeFormat = '12',
$selected = null, $attributes = array(), $showEmpty = true) {
...
case 'm':
$selectMonthAttr['monthNames'] = $monthNames;
$selects[] = $this->month($fieldName, $month, $selectMonthAttr,
$showEmpty, true);
break;
...
}
}}}
== Use ==
{{{
#!php
echo $form->input('Date.date', array('dateFormat' => 'mDY'))
}}}
== Why Does Cake Need This? ==
A good situation was my current project that has constraints on document
size; according to the specifications, I had to fit a date and time
selection onto a single line. I had to set a width for the select element
to fit everything on one line (645px document width). The select box for
the month drop-down looked horrible. It was a perfect size for a short-
date syntax, but nothing such existed.
--
Ticket URL: <https://trac.cakephp.org/ticket/6079>
CakePHP : The Rapid Development Framework for PHP <https://trac.cakephp.org/>
Cake is a rapid development framework for PHP which uses commonly known design
patterns like ActiveRecord, Association Data Mapping, Front Controller and MVC.
Our primary goal is to provide a structured framework that enables PHP users at
all levels to rapidly develop robust web applications, without any loss to
flexibility.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"tickets cakephp" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/tickets-cakephp?hl=en
-~----------~----~----~----~------~----~------~--~---