updating FormHelper::inputs(), closes #3325 and closes #3324, tests added

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5758 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
gwoo 2007-10-14 23:41:05 +00:00
parent b61f559030
commit a3fc6e4af5
2 changed files with 42 additions and 33 deletions

View file

@ -38,7 +38,8 @@ class FormHelper extends AppHelper {
/** /**
* Other helpers used by FormHelper * Other helpers used by FormHelper
* *
* @var unknown_type * @var array
* @access public
*/ */
var $helpers = array('Html'); var $helpers = array('Html');
/** /**
@ -51,7 +52,7 @@ class FormHelper extends AppHelper {
/** /**
* Enter description here... * Enter description here...
* *
* @var unknown_type * @var array
*/ */
var $__options = array( var $__options = array(
'day' => array(), 'minute' => array(), 'hour' => array(), 'day' => array(), 'minute' => array(), 'hour' => array(),
@ -61,12 +62,14 @@ class FormHelper extends AppHelper {
* Enter description here... * Enter description here...
* *
* @var array * @var array
* @access public
*/ */
var $fields = array(); var $fields = array();
/** /**
* Defines the type of form being created. Set by FormHelper::create(). * Defines the type of form being created. Set by FormHelper::create().
* *
* @var string * @var string
* @access public
*/ */
var $requestType = null; var $requestType = null;
/** /**
@ -145,7 +148,6 @@ class FormHelper extends AppHelper {
$created = true; $created = true;
$id = $this->data[$model][$data['key']]; $id = $this->data[$model][$data['key']];
} }
$view->modelId = $id;
$options = am(array( $options = am(array(
'type' => ($created && empty($options['action'])) ? 'put' : 'post', 'type' => ($created && empty($options['action'])) ? 'put' : 'post',
'action' => null, 'action' => null,
@ -401,7 +403,7 @@ class FormHelper extends AppHelper {
if (substr($text, -3) == '_id') { if (substr($text, -3) == '_id') {
$text = substr($text, 0, strlen($text) - 3); $text = substr($text, 0, strlen($text) - 3);
} }
$text = Inflector::humanize($text); $text = Inflector::humanize(Inflector::underscore($text));
} }
if (isset($attributes['for'])) { if (isset($attributes['for'])) {
@ -424,29 +426,36 @@ class FormHelper extends AppHelper {
* @param array $blacklist a simple array of fields to skip * @param array $blacklist a simple array of fields to skip
* @return output * @return output
*/ */
function inputs($fields = null, $blacklist = null) { function inputs($fields = true, $blacklist = null) {
if (!is_array($fields)) { if (is_array($fields)) {
$fieldset = $fields; if (array_key_exists('legend', $fields)) {
$fields = array_keys($this->fieldset['fields']); $legend = $fields['legend'];
} unset($fields['legend']);
if (isset($fields['fieldset'])) {
$fieldset = $fields['fieldset'];
unset($fields['fieldset']);
} else {
$fieldset = true;
} }
if ($fieldset === true) { if (isset($fields['fieldset'])) {
$fields = $fields['fieldset'];
unset($fields['fieldset']);
}
} else {
$legend = $fields;
unset($fields);
}
if (empty($fields)) {
$fields = array_keys($this->fieldset['fields']);
}
if ($legend === true) {
$legend = 'New '; $legend = 'New ';
if (in_array($this->action, array('update', 'edit'))) { $prefix = null;
if (isset($this->params['prefix'])) {
$prefix = $this->params['prefix'];
}
if (in_array(str_replace($prefix .'_', '', $this->action), array('update', 'edit'))) {
$legend = 'Edit '; $legend = 'Edit ';
} }
$legend .= Inflector::humanize(Inflector::underscore($this->model())); $legend .= Inflector::humanize(Inflector::underscore($this->model()));
} elseif (is_string($fieldset)) {
$legend = $fieldset;
} elseif (isset($fieldset['legend'])) {
$legend = $fields['legend'];
unset($fields['legend']);
} }
$out = null; $out = null;
@ -455,18 +464,6 @@ class FormHelper extends AppHelper {
$name = $options; $name = $options;
$options = array(); $options = array();
} }
if (is_array($options) && isset($options['fieldset'])) {
$out .= $this->inputs($options);
continue;
}
if (is_array($options) && isset($options['fieldName'])) {
$name = $options['fieldName'];
unset($options['fieldName']);
}
if (isset($options['blacklist'])) {
$blacklist = $options['blacklist'];
unset($options['blacklist']);
}
if (is_array($blacklist) && in_array($name, $blacklist)) { if (is_array($blacklist) && in_array($name, $blacklist)) {
continue; continue;
} }

View file

@ -362,6 +362,18 @@ class FormHelperTest extends CakeTestCase {
$this->assertNoPattern('/error-message/', $result); $this->assertNoPattern('/error-message/', $result);
} }
function testFormInputs() {
$this->Form->create('Contact');
$result = $this->Form->inputs('The Legend');
$this->assertPattern('/<legend>The Legend<\/legend>/', $result);
$this->Form->params['prefix'] = 'admin';
$this->Form->action = 'admin_edit';
$result = $this->Form->inputs();
$this->assertPattern('/<legend>Edit Contact<\/legend>/', $result);
}
function testLabel() { function testLabel() {
$this->Form->text('Person/name'); $this->Form->text('Person/name');
$result = $this->Form->label(); $result = $this->Form->label();