mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2025-01-19 02:56:15 +00:00
updating formHelper for #1035 adding more tests, fixing some tags the would produce spaces
git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5181 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
parent
00b450929e
commit
5a0832f086
3 changed files with 207 additions and 103 deletions
|
@ -338,20 +338,20 @@ class FormHelper extends AppHelper {
|
||||||
/**
|
/**
|
||||||
* Returns a formatted LABEL element for HTML FORMs.
|
* Returns a formatted LABEL element for HTML FORMs.
|
||||||
*
|
*
|
||||||
* @param string $tagName This should be "Modelname.fieldname", "Modelname/fieldname" is deprecated
|
* @param string $fieldName This should be "Modelname.fieldname", "Modelname/fieldname" is deprecated
|
||||||
* @param string $text Text that will appear in the label field.
|
* @param string $text Text that will appear in the label field.
|
||||||
* @return string The formatted LABEL element
|
* @return string The formatted LABEL element
|
||||||
*/
|
*/
|
||||||
function label($tagName = null, $text = null, $attributes = array()) {
|
function label($fieldName = null, $text = null, $attributes = array()) {
|
||||||
if (empty($tagName)) {
|
if (empty($fieldName)) {
|
||||||
$tagName = implode('.', array_filter(array($this->model(), $this->field())));
|
$fieldName = implode('.', array_filter(array($this->model(), $this->field())));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($text === null) {
|
if ($text === null) {
|
||||||
if (strpos($tagName, '/') !== false || strpos($tagName, '.') !== false) {
|
if (strpos($fieldName, '/') !== false || strpos($fieldName, '.') !== false) {
|
||||||
list( , $text) = preg_split('/[\/\.]+/', $tagName);
|
list( , $text) = preg_split('/[\/\.]+/', $fieldName);
|
||||||
} else {
|
} else {
|
||||||
$text = $tagName;
|
$text = $fieldName;
|
||||||
}
|
}
|
||||||
if (substr($text, -3) == '_id') {
|
if (substr($text, -3) == '_id') {
|
||||||
$text = substr($text, 0, strlen($text) - 3);
|
$text = substr($text, 0, strlen($text) - 3);
|
||||||
|
@ -363,13 +363,13 @@ class FormHelper extends AppHelper {
|
||||||
$labelFor = $attributes['for'];
|
$labelFor = $attributes['for'];
|
||||||
unset($attributes['for']);
|
unset($attributes['for']);
|
||||||
} else {
|
} else {
|
||||||
$labelFor = $this->domId($tagName);
|
$labelFor = $this->domId($fieldName);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->output(sprintf($this->Html->tags['label'], $labelFor, $this->_parseAttributes($attributes), $text));
|
return $this->output(sprintf($this->Html->tags['label'], $labelFor, $this->_parseAttributes($attributes), $text));
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Will display all the fields passed in an array expects tagName as an array key
|
* Will display all the fields passed in an array expects fieldName as an array key
|
||||||
* replaces generateFields
|
* replaces generateFields
|
||||||
*
|
*
|
||||||
* @access public
|
* @access public
|
||||||
|
@ -411,9 +411,9 @@ class FormHelper extends AppHelper {
|
||||||
$name = $options;
|
$name = $options;
|
||||||
$options = array();
|
$options = array();
|
||||||
}
|
}
|
||||||
if(is_array($options) && isset($options['tagName'])) {
|
if(is_array($options) && isset($options['fieldName'])) {
|
||||||
$name = $options['tagName'];
|
$name = $options['fieldName'];
|
||||||
unset($options['tagName']);
|
unset($options['fieldName']);
|
||||||
}
|
}
|
||||||
$out .= $this->input($name, $options);
|
$out .= $this->input($name, $options);
|
||||||
}
|
}
|
||||||
|
@ -426,12 +426,12 @@ class FormHelper extends AppHelper {
|
||||||
/**
|
/**
|
||||||
* Generates a form input element complete with label and wrapper div
|
* Generates a form input element complete with label and wrapper div
|
||||||
*
|
*
|
||||||
* @param string $tagName This should be "Modelname.fieldname", "Modelname/fieldname" is deprecated
|
* @param string $fieldName This should be "Modelname.fieldname", "Modelname/fieldname" is deprecated
|
||||||
* @param array $options
|
* @param array $options
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function input($tagName, $options = array()) {
|
function input($fieldName, $options = array()) {
|
||||||
$this->setFormTag($tagName);
|
$this->setFormTag($fieldName);
|
||||||
$options = am(
|
$options = am(
|
||||||
array(
|
array(
|
||||||
'before' => null,
|
'before' => null,
|
||||||
|
@ -565,42 +565,42 @@ class FormHelper extends AppHelper {
|
||||||
|
|
||||||
switch ($type) {
|
switch ($type) {
|
||||||
case 'hidden':
|
case 'hidden':
|
||||||
$out = $this->hidden($tagName, $options);
|
$out = $this->hidden($fieldName, $options);
|
||||||
unset($divOptions);
|
unset($divOptions);
|
||||||
break;
|
break;
|
||||||
case 'checkbox':
|
case 'checkbox':
|
||||||
$out = $before . $this->checkbox($tagName, $options) . $between . $out;
|
$out = $before . $this->checkbox($fieldName, $options) . $between . $out;
|
||||||
break;
|
break;
|
||||||
case 'text':
|
case 'text':
|
||||||
case 'password':
|
case 'password':
|
||||||
$out = $before . $out . $between . $this->{$type}($tagName, $options);
|
$out = $before . $out . $between . $this->{$type}($fieldName, $options);
|
||||||
break;
|
break;
|
||||||
case 'file':
|
case 'file':
|
||||||
$out = $before . $out . $between . $this->file($tagName, $options);
|
$out = $before . $out . $between . $this->file($fieldName, $options);
|
||||||
break;
|
break;
|
||||||
case 'select':
|
case 'select':
|
||||||
$options = am(array('options' => array()), $options);
|
$options = am(array('options' => array()), $options);
|
||||||
$list = $options['options'];
|
$list = $options['options'];
|
||||||
unset($options['options']);
|
unset($options['options']);
|
||||||
$out = $before . $out . $between . $this->select($tagName, $list, $selected, $options, $empty);
|
$out = $before . $out . $between . $this->select($fieldName, $list, $selected, $options, $empty);
|
||||||
break;
|
break;
|
||||||
case 'time':
|
case 'time':
|
||||||
$out = $before . $out . $between . $this->dateTime($tagName, null, '12', $selected, $options, $empty);
|
$out = $before . $out . $between . $this->dateTime($fieldName, null, '12', $selected, $options, $empty);
|
||||||
break;
|
break;
|
||||||
case 'date':
|
case 'date':
|
||||||
$out = $before . $out . $between . $this->dateTime($tagName, 'MDY', null, $selected, $options, $empty);
|
$out = $before . $out . $between . $this->dateTime($fieldName, 'MDY', null, $selected, $options, $empty);
|
||||||
break;
|
break;
|
||||||
case 'datetime':
|
case 'datetime':
|
||||||
$out = $before . $out . $between . $this->dateTime($tagName, 'MDY', '12', $selected, $options, $empty);
|
$out = $before . $out . $between . $this->dateTime($fieldName, 'MDY', '12', $selected, $options, $empty);
|
||||||
break;
|
break;
|
||||||
case 'textarea':
|
case 'textarea':
|
||||||
default:
|
default:
|
||||||
$out = $before . $out . $between . $this->textarea($tagName, am(array('cols' => '30', 'rows' => '6'), $options));
|
$out = $before . $out . $between . $this->textarea($fieldName, am(array('cols' => '30', 'rows' => '6'), $options));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($type != 'hidden' && $error !== false) {
|
if ($type != 'hidden' && $error !== false) {
|
||||||
$out .= $this->error($tagName, $error);
|
$out .= $this->error($fieldName, $error);
|
||||||
$out .= $after;
|
$out .= $after;
|
||||||
}
|
}
|
||||||
if (isset($divOptions)) {
|
if (isset($divOptions)) {
|
||||||
|
@ -863,7 +863,7 @@ class FormHelper extends AppHelper {
|
||||||
$tag = $this->Html->tags['selectstart'];
|
$tag = $this->Html->tags['selectstart'];
|
||||||
$this->__secure();
|
$this->__secure();
|
||||||
}
|
}
|
||||||
$select[] = sprintf($tag, $this->model(), $this->field(), $this->Html->_parseAttributes($attributes));
|
$select[] = sprintf($tag, $this->model(), $this->field(), $this->_parseAttributes($attributes));
|
||||||
|
|
||||||
if ($showEmpty !== null && $showEmpty !== false) {
|
if ($showEmpty !== null && $showEmpty !== false) {
|
||||||
if($showEmpty === true) {
|
if($showEmpty === true) {
|
||||||
|
@ -887,11 +887,18 @@ class FormHelper extends AppHelper {
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function day($fieldName, $selected = null, $attributes = array(), $showEmpty = true) {
|
function day($fieldName, $selected = null, $attributes = array(), $showEmpty = true) {
|
||||||
if (empty($selected) && $value = $this->__value($fieldName)) {
|
$value = $this->__value($fieldName);
|
||||||
$selected = date('d', strtotime($value));
|
if (empty($value)) {
|
||||||
|
if(!$showEmpty) {
|
||||||
|
$value = 'now';
|
||||||
|
} else if(strlen($selected) > 2) {
|
||||||
|
$value = $selected;
|
||||||
|
} else if($selected === false) {
|
||||||
|
$selected = null;
|
||||||
}
|
}
|
||||||
if (empty($selected) && !$showEmpty) {
|
}
|
||||||
$selected = date('d');
|
if(!empty($value)) {
|
||||||
|
$selected = date('d', strtotime($value));
|
||||||
}
|
}
|
||||||
return $this->select($fieldName . "_day", $this->__generateOptions('day'), $selected, $attributes, $showEmpty);
|
return $this->select($fieldName . "_day", $this->__generateOptions('day'), $selected, $attributes, $showEmpty);
|
||||||
}
|
}
|
||||||
|
@ -907,98 +914,123 @@ class FormHelper extends AppHelper {
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function year($fieldName, $minYear = null, $maxYear = null, $selected = null, $attributes = array(), $showEmpty = true) {
|
function year($fieldName, $minYear = null, $maxYear = null, $selected = null, $attributes = array(), $showEmpty = true) {
|
||||||
if (empty($selected) && $value = $this->__value($fieldName)) {
|
$value = $this->__value($fieldName);
|
||||||
$selected = date('Y', strtotime($value));
|
if (empty($value)) {
|
||||||
|
if(!$showEmpty && !$maxYear) {
|
||||||
|
$value = 'now';
|
||||||
|
} else if(!$showEmpty && $maxYear) {
|
||||||
|
$selected = $maxYear;
|
||||||
|
} else if(strlen($selected) > 4) {
|
||||||
|
$value = $selected;
|
||||||
|
} else if($selected === false) {
|
||||||
|
$selected = null;
|
||||||
}
|
}
|
||||||
if (empty($selected) && !$showEmpty) {
|
}
|
||||||
$selected = date('Y');
|
if(!empty($value)) {
|
||||||
|
$selected = date('Y', strtotime($value));
|
||||||
}
|
}
|
||||||
return $this->select($fieldName . "_year", $this->__generateOptions('year', $minYear, $maxYear), $selected, $attributes, $showEmpty);
|
return $this->select($fieldName . "_year", $this->__generateOptions('year', $minYear, $maxYear), $selected, $attributes, $showEmpty);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Returns a SELECT element for months.
|
* Returns a SELECT element for months.
|
||||||
*
|
*
|
||||||
* @param string $tagName Prefix name for the SELECT element
|
* @param string $fieldName Prefix name for the SELECT element
|
||||||
* @param string $selected Option which is selected.
|
* @param string $selected Option which is selected.
|
||||||
* @param boolean $showEmpty Show/hide the empty select option
|
* @param boolean $showEmpty Show/hide the empty select option
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function month($tagName, $selected = null, $attributes = array(), $showEmpty = true) {
|
function month($fieldName, $selected = null, $attributes = array(), $showEmpty = true) {
|
||||||
if (empty($selected) && $value = $this->__value($tagName)) {
|
$value = $this->__value($fieldName);
|
||||||
|
if (empty($value)) {
|
||||||
|
if(!$showEmpty) {
|
||||||
|
$value = 'now';
|
||||||
|
} else if(strlen($selected) > 2) {
|
||||||
|
$value = $selected;
|
||||||
|
} else if($selected === false) {
|
||||||
|
$selected = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!empty($value)) {
|
||||||
$selected = date('m', strtotime($value));
|
$selected = date('m', strtotime($value));
|
||||||
}
|
}
|
||||||
$selected = empty($selected) ? ($showEmpty ? NULL : date('m')) : $selected;
|
return $this->select($fieldName . "_month", $this->__generateOptions('month'), $selected, $attributes, $showEmpty);
|
||||||
return $this->select($tagName . "_month", $this->__generateOptions('month'), $selected, $attributes, $showEmpty);
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Returns a SELECT element for hours.
|
* Returns a SELECT element for hours.
|
||||||
*
|
*
|
||||||
* @param string $tagName Prefix name for the SELECT element
|
* @param string $fieldName Prefix name for the SELECT element
|
||||||
* @param boolean $format24Hours True for 24 hours format
|
* @param boolean $format24Hours True for 24 hours format
|
||||||
* @param string $selected Option which is selected.
|
* @param string $selected Option which is selected.
|
||||||
* @param array $attributes List of HTML attributes
|
* @param array $attributes List of HTML attributes
|
||||||
* @param mixed $showEmpty True to show an empty element, or a string to provide default empty element text
|
* @param mixed $showEmpty True to show an empty element, or a string to provide default empty element text
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function hour($tagName, $format24Hours = false, $selected = null, $attributes = array(), $showEmpty = true) {
|
function hour($fieldName, $format24Hours = false, $selected = null, $attributes = array(), $showEmpty = true) {
|
||||||
if (empty($selected) && $value = $this->__value($tagName)) {
|
$value = $this->__value($fieldName);
|
||||||
if ($format24Hours) {
|
if (empty($value)) {
|
||||||
|
if(!$showEmpty) {
|
||||||
|
$value = 'now';
|
||||||
|
} else if(strlen($selected) > 2) {
|
||||||
|
$value = $selected;
|
||||||
|
} else if($selected === false) {
|
||||||
|
$selected = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!empty($value) && $format24Hours) {
|
||||||
$selected = date('H', strtotime($value));
|
$selected = date('H', strtotime($value));
|
||||||
} else {
|
} else if(!empty($value) && !$format24Hours) {
|
||||||
$selected = date('g', strtotime($value));
|
$selected = date('g', strtotime($value));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if ($format24Hours) {
|
return $this->select($fieldName . "_hour", $this->__generateOptions($format24Hours ? 'hour24' : 'hour'), $selected, $attributes, $showEmpty);
|
||||||
$selected = empty($selected) ? ($showEmpty ? NULL : date('H')) : $selected;
|
|
||||||
} else {
|
|
||||||
$hourValue = empty($selected) ? ($showEmpty ? NULL : date('g')) : $selected;
|
|
||||||
if (isset($selected) && intval($hourValue) == 0 && !$showEmpty) {
|
|
||||||
$selected = 12;
|
|
||||||
} else {
|
|
||||||
$selected = $hourValue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $this->select($tagName . "_hour", $this->__generateOptions($format24Hours ? 'hour24' : 'hour'), $selected, $attributes, $showEmpty);
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Returns a SELECT element for minutes.
|
* Returns a SELECT element for minutes.
|
||||||
*
|
*
|
||||||
* @param string $tagName Prefix name for the SELECT element
|
* @param string $fieldName Prefix name for the SELECT element
|
||||||
* @param string $selected Option which is selected.
|
* @param string $selected Option which is selected.
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function minute($tagName, $selected = null, $attributes = array(), $showEmpty = true) {
|
function minute($fieldName, $selected = null, $attributes = array(), $showEmpty = true) {
|
||||||
if (empty($selected) && $value = $this->__value($tagName)) {
|
$value = $this->__value($fieldName);
|
||||||
|
if (empty($value)) {
|
||||||
|
if(!$showEmpty) {
|
||||||
|
$value = 'now';
|
||||||
|
} else if(strlen($selected) > 2) {
|
||||||
|
$value = $selected;
|
||||||
|
} else if($selected === false) {
|
||||||
|
$selected = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(!empty($value)) {
|
||||||
$selected = date('i', strtotime($value));
|
$selected = date('i', strtotime($value));
|
||||||
}
|
}
|
||||||
$selected = empty($selected) ? ($showEmpty ? NULL : date('i')) : $selected;
|
return $this->select($fieldName . "_min", $this->__generateOptions('minute'), $selected, $attributes, $showEmpty);
|
||||||
return $this->select($tagName . "_min", $this->__generateOptions('minute'), $selected, $attributes, $showEmpty);
|
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Returns a SELECT element for AM or PM.
|
* Returns a SELECT element for AM or PM.
|
||||||
*
|
*
|
||||||
* @param string $tagName Prefix name for the SELECT element
|
* @param string $fieldName Prefix name for the SELECT element
|
||||||
* @param string $selected Option which is selected.
|
* @param string $selected Option which is selected.
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
function meridian($tagName, $selected = null, $attributes = array(), $showEmpty = true) {
|
function meridian($fieldName, $selected = null, $attributes = array(), $showEmpty = true) {
|
||||||
if (empty($selected) && $value = $this->__value($tagName)) {
|
if (empty($selected) && $value = $this->__value($fieldName)) {
|
||||||
$selected = date('a', strtotime($value));
|
$selected = date('a', strtotime($value));
|
||||||
}
|
}
|
||||||
$selected = empty($selected) ? ($showEmpty ? null : date('a')) : $selected;
|
$selected = empty($selected) ? ($showEmpty ? null : date('a')) : $selected;
|
||||||
return $this->select($tagName . "_meridian", $this->__generateOptions('meridian'), $selected, $attributes, $showEmpty);
|
return $this->select($fieldName . "_meridian", $this->__generateOptions('meridian'), $selected, $attributes, $showEmpty);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Returns a set of SELECT elements for a full datetime setup: day, month and year, and then time.
|
* Returns a set of SELECT elements for a full datetime setup: day, month and year, and then time.
|
||||||
*
|
*
|
||||||
* @param string $tagName Prefix name for the SELECT element
|
* @param string $fieldName Prefix name for the SELECT element
|
||||||
* @param string $dateFormat DMY, MDY, YMD or NONE.
|
* @param string $dateFormat DMY, MDY, YMD or NONE.
|
||||||
* @param string $timeFormat 12, 24, NONE
|
* @param string $timeFormat 12, 24, NONE
|
||||||
* @param string $selected Option which is selected.
|
* @param string $selected Option which is selected.
|
||||||
* @return string The HTML formatted OPTION element
|
* @return string The HTML formatted OPTION element
|
||||||
*/
|
*/
|
||||||
function dateTime($tagName, $dateFormat = 'DMY', $timeFormat = '12', $selected = null, $attributes = array(), $showEmpty = true) {
|
function dateTime($fieldName, $dateFormat = 'DMY', $timeFormat = '12', $selected = null, $attributes = array(), $showEmpty = true) {
|
||||||
$day = null;
|
$day = null;
|
||||||
$month = null;
|
$month = null;
|
||||||
$year = null;
|
$year = null;
|
||||||
|
@ -1007,7 +1039,7 @@ class FormHelper extends AppHelper {
|
||||||
$meridian = null;
|
$meridian = null;
|
||||||
|
|
||||||
if (empty($selected)) {
|
if (empty($selected)) {
|
||||||
$selected = $this->__value($tagName);
|
$selected = $this->__value($fieldName);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!empty($selected)) {
|
if (!empty($selected)) {
|
||||||
|
@ -1073,20 +1105,20 @@ class FormHelper extends AppHelper {
|
||||||
|
|
||||||
switch($dateFormat) {
|
switch($dateFormat) {
|
||||||
case 'DMY': // so uses the new selex
|
case 'DMY': // so uses the new selex
|
||||||
$opt = $this->day($tagName, $day, $selectDayAttr, $showEmpty) . '-' .
|
$opt = $this->day($fieldName, $day, $selectDayAttr, $showEmpty) . '-' .
|
||||||
$this->month($tagName, $month, $selectMonthAttr, $showEmpty) . '-' . $this->year($tagName, $attributes['minYear'], $attributes['maxYear'], $year, $selectYearAttr, $showEmpty);
|
$this->month($fieldName, $month, $selectMonthAttr, $showEmpty) . '-' . $this->year($fieldName, $attributes['minYear'], $attributes['maxYear'], $year, $selectYearAttr, $showEmpty);
|
||||||
break;
|
break;
|
||||||
case 'MDY':
|
case 'MDY':
|
||||||
$opt = $this->month($tagName, $month, $selectMonthAttr, $showEmpty) . '-' .
|
$opt = $this->month($fieldName, $month, $selectMonthAttr, $showEmpty) . '-' .
|
||||||
$this->day($tagName, $day, $selectDayAttr, $showEmpty) . '-' . $this->year($tagName, $attributes['minYear'], $attributes['maxYear'], $year, $selectYearAttr, $showEmpty);
|
$this->day($fieldName, $day, $selectDayAttr, $showEmpty) . '-' . $this->year($fieldName, $attributes['minYear'], $attributes['maxYear'], $year, $selectYearAttr, $showEmpty);
|
||||||
break;
|
break;
|
||||||
case 'YMD':
|
case 'YMD':
|
||||||
$opt = $this->year($tagName, $attributes['minYear'], $attributes['maxYear'], $year, $selectYearAttr, $showEmpty) . '-' .
|
$opt = $this->year($fieldName, $attributes['minYear'], $attributes['maxYear'], $year, $selectYearAttr, $showEmpty) . '-' .
|
||||||
$this->month($tagName, $month, $selectMonthAttr, $showEmpty) . '-' .
|
$this->month($fieldName, $month, $selectMonthAttr, $showEmpty) . '-' .
|
||||||
$this->day($tagName, $day, $selectDayAttr, $showEmpty);
|
$this->day($fieldName, $day, $selectDayAttr, $showEmpty);
|
||||||
break;
|
break;
|
||||||
case 'Y':
|
case 'Y':
|
||||||
$opt = $this->year($tagName, $attributes['minYear'], $attributes['maxYear'], $selected, $selectYearAttr, $showEmpty);
|
$opt = $this->year($fieldName, $attributes['minYear'], $attributes['maxYear'], $selected, $selectYearAttr, $showEmpty);
|
||||||
break;
|
break;
|
||||||
case 'NONE':
|
case 'NONE':
|
||||||
default:
|
default:
|
||||||
|
@ -1096,13 +1128,13 @@ class FormHelper extends AppHelper {
|
||||||
|
|
||||||
switch($timeFormat) {
|
switch($timeFormat) {
|
||||||
case '24':
|
case '24':
|
||||||
$opt .= $this->hour($tagName, true, $hour, $selectHourAttr, $showEmpty) . ':' .
|
$opt .= $this->hour($fieldName, true, $hour, $selectHourAttr, $showEmpty) . ':' .
|
||||||
$this->minute($tagName, $min, $selectMinuteAttr, $showEmpty);
|
$this->minute($fieldName, $min, $selectMinuteAttr, $showEmpty);
|
||||||
break;
|
break;
|
||||||
case '12':
|
case '12':
|
||||||
$opt .= $this->hour($tagName, false, $hour, $selectHourAttr, $showEmpty) . ':' .
|
$opt .= $this->hour($fieldName, false, $hour, $selectHourAttr, $showEmpty) . ':' .
|
||||||
$this->minute($tagName, $min, $selectMinuteAttr, $showEmpty) . ' ' .
|
$this->minute($fieldName, $min, $selectMinuteAttr, $showEmpty) . ' ' .
|
||||||
$this->meridian($tagName, $meridian, $selectMeridianAttr, $showEmpty);
|
$this->meridian($fieldName, $meridian, $selectMeridianAttr, $showEmpty);
|
||||||
break;
|
break;
|
||||||
case 'NONE':
|
case 'NONE':
|
||||||
default:
|
default:
|
||||||
|
|
|
@ -574,18 +574,49 @@ class FormHelperTest extends CakeTestCase {
|
||||||
'/i', $result);
|
'/i', $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testDaySelect() {
|
function testDay() {
|
||||||
|
$result = $this->Form->day('Model.field', false);
|
||||||
|
$this->assertPattern('/option value="12"/', $result);
|
||||||
|
$this->assertPattern('/option value="13"/', $result);
|
||||||
|
|
||||||
|
$this->Form->data['Model']['field'] = '10-10-2006 23:12:32';
|
||||||
|
$result = $this->Form->day('Model.field');
|
||||||
|
$this->assertPattern('/option value="10" selected="selected"/', $result);
|
||||||
|
$this->assertNoPattern('/option value="32"/', $result);
|
||||||
|
|
||||||
|
$this->Form->data['Model']['field'] = '';
|
||||||
|
$result = $this->Form->day('Model.field', '10');
|
||||||
|
$this->assertPattern('/option value="10" selected="selected"/', $result);
|
||||||
|
$this->assertPattern('/option value="23"/', $result);
|
||||||
|
$this->assertPattern('/option value="24"/', $result);
|
||||||
|
|
||||||
|
$this->Form->data['Model']['field'] = '10-10-2006 23:12:32';
|
||||||
|
$result = $this->Form->day('Model.field', true);
|
||||||
|
$this->assertPattern('/option value="10" selected="selected"/', $result);
|
||||||
|
$this->assertPattern('/option value="23"/', $result);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function testHour() {
|
function testHour() {
|
||||||
$result = $this->Form->hour('tagname', false);
|
$result = $this->Form->hour('Model.field', false);
|
||||||
$this->assertPattern('/option value="12"/', $result);
|
$this->assertPattern('/option value="12"/', $result);
|
||||||
$this->assertNoPattern('/option value="13"/', $result);
|
$this->assertNoPattern('/option value="13"/', $result);
|
||||||
|
|
||||||
$result = $this->Form->hour('tagname', true);
|
$this->Form->data['Model']['field'] = '10-10-2006 00:12:32';
|
||||||
|
$result = $this->Form->hour('Model.field', false);
|
||||||
|
$this->assertPattern('/option value="12" selected="selected"/', $result);
|
||||||
|
$this->assertNoPattern('/option value="13"/', $result);
|
||||||
|
|
||||||
|
$this->Form->data['Model']['field'] = '';
|
||||||
|
$result = $this->Form->hour('Model.field', true);
|
||||||
$this->assertPattern('/option value="23"/', $result);
|
$this->assertPattern('/option value="23"/', $result);
|
||||||
$this->assertNoPattern('/option value="24"/', $result);
|
$this->assertNoPattern('/option value="24"/', $result);
|
||||||
|
|
||||||
|
$this->Form->data['Model']['field'] = '10-10-2006 00:12:32';
|
||||||
|
$result = $this->Form->hour('Model.field', true);
|
||||||
|
$this->assertPattern('/option value="23"/', $result);
|
||||||
|
$this->assertPattern('/option value="00" selected="selected"/', $result);
|
||||||
|
$this->assertNoPattern('/option value="24"/', $result);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testYear() {
|
function testYear() {
|
||||||
|
@ -594,6 +625,47 @@ class FormHelperTest extends CakeTestCase {
|
||||||
$this->assertPattern('/option value="2007"/', $result);
|
$this->assertPattern('/option value="2007"/', $result);
|
||||||
$this->assertNoPattern('/option value="2005"/', $result);
|
$this->assertNoPattern('/option value="2005"/', $result);
|
||||||
$this->assertNoPattern('/option value="2008"/', $result);
|
$this->assertNoPattern('/option value="2008"/', $result);
|
||||||
|
|
||||||
|
$this->data['Model']['field'] = '';
|
||||||
|
$result = $this->Form->year('Model.field', 2006, 2007, null, array('class'=>'year'));
|
||||||
|
$expecting = "<select name=\"data[Model][field_year]\" class=\"year\" id=\"ModelFieldYear\">\n<option value=\"\"></option>\n<option value=\"2006\">2006</option>\n<option value=\"2007\">2007</option>\n</select>";
|
||||||
|
$this->assertEqual($result, $expecting);
|
||||||
|
|
||||||
|
$this->Form->data['Model']['field'] = '10-10-2006';
|
||||||
|
$result = $this->Form->year('Model.field', 2006, 2007, null, array(), false);
|
||||||
|
$expecting = "<select name=\"data[Model][field_year]\" id=\"ModelFieldYear\">\n<option value=\"2006\" selected=\"selected\">2006</option>\n<option value=\"2007\">2007</option>\n</select>";
|
||||||
|
$this->assertEqual($result, $expecting);
|
||||||
|
|
||||||
|
$this->Form->data['Model']['field'] = '';
|
||||||
|
$result = $this->Form->year('Model.field', 2006, 2007, false);
|
||||||
|
$expecting = "<select name=\"data[Model][field_year]\" id=\"ModelFieldYear\">\n<option value=\"\"></option>\n<option value=\"2006\">2006</option>\n<option value=\"2007\">2007</option>\n</select>";
|
||||||
|
$this->assertEqual($result, $expecting);
|
||||||
|
|
||||||
|
$this->Form->data['Model']['field'] = '10-10-2006';
|
||||||
|
$result = $this->Form->year('Model.field', 2006, 2007, false, array(), false);
|
||||||
|
$expecting = "<select name=\"data[Model][field_year]\" id=\"ModelFieldYear\">\n<option value=\"2006\" selected=\"selected\">2006</option>\n<option value=\"2007\">2007</option>\n</select>";
|
||||||
|
$this->assertEqual($result, $expecting);
|
||||||
|
|
||||||
|
$this->Form->data['Model']['field'] = '';
|
||||||
|
$result = $this->Form->year('Model.field', 2006, 2007, '2007');
|
||||||
|
$expecting = "<select name=\"data[Model][field_year]\" id=\"ModelFieldYear\">\n<option value=\"\"></option>\n<option value=\"2006\">2006</option>\n<option value=\"2007\" selected=\"selected\">2007</option>\n</select>";
|
||||||
|
$this->assertEqual($result, $expecting);
|
||||||
|
|
||||||
|
$this->Form->data['Model']['field'] = '10-10-2006';
|
||||||
|
$result = $this->Form->year('Model.field', 2006, 2007, '2007', array(), false);
|
||||||
|
$expecting = "<select name=\"data[Model][field_year]\" id=\"ModelFieldYear\">\n<option value=\"2006\" selected=\"selected\">2006</option>\n<option value=\"2007\">2007</option>\n</select>";
|
||||||
|
$this->assertEqual($result, $expecting);
|
||||||
|
|
||||||
|
$this->Form->data['Model']['field'] = '';
|
||||||
|
$result = $this->Form->year('Model.field', 2006, 2008, null, array(), false);
|
||||||
|
$expecting = "<select name=\"data[Model][field_year]\" id=\"ModelFieldYear\">\n<option value=\"2006\">2006</option>\n<option value=\"2007\">2007</option>\n<option value=\"2008\" selected=\"selected\">2008</option>\n</select>";
|
||||||
|
$this->assertEqual($result, $expecting);
|
||||||
|
|
||||||
|
$this->Form->data['Model']['field'] = '10-10-2006';
|
||||||
|
$result = $this->Form->year('Model.field', 2006, 2008, null, array(), false);
|
||||||
|
$expecting = "<select name=\"data[Model][field_year]\" id=\"ModelFieldYear\">\n<option value=\"2006\" selected=\"selected\">2006</option>\n<option value=\"2007\">2007</option>\n<option value=\"2008\">2008</option>\n</select>";
|
||||||
|
$this->assertEqual($result, $expecting);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function testTextArea() {
|
function testTextArea() {
|
||||||
|
|
Loading…
Add table
Reference in a new issue