Adding fix for #2614

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@5145 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
phpnut 2007-05-21 05:15:26 +00:00
parent 7fb6896ab6
commit 84de5b6e35
2 changed files with 31 additions and 31 deletions

View file

@ -358,14 +358,14 @@ class FormHelper extends AppHelper {
}
$text = Inflector::humanize($text);
}
if (isset($attributes['for'])) {
$labelFor = $attributes['for'];
unset($attributes['for']);
} else {
$labelFor = $this->domId($tagName);
}
return $this->output(sprintf($this->Html->tags['label'], $labelFor, $this->_parseAttributes($attributes), $text));
}
/**
@ -381,7 +381,7 @@ class FormHelper extends AppHelper {
if(!is_array($fields)) {
$fieldset = $fields;
$fields = array_keys($this->fieldset['fields']);
}
}
if(isset($fields['fieldset'])) {
$fieldset = $fields['fieldset'];
unset($fields['fieldset']);
@ -512,27 +512,27 @@ class FormHelper extends AppHelper {
$label = $options['label'];
unset($options['label']);
}
if ($label !== false) {
$labelAttributes = array();
if (in_array($options['type'], array('date', 'datetime'))) {
$labelFor = $this->domId(implode('.', array_filter(array($this->model(), $this->field()))));
$labelAttributes = array( 'for' => $labelFor . 'Month' );
}
if (is_array($label)) {
$labelText = null;
if (isset($label['text'])) {
$labelText = $label['text'];
unset($label['text']);
}
$labelAttributes = am($labelAttributes, $label);
} else {
$labelText = $label;
}
$out = $this->label(null, $labelText, $labelAttributes);
}
@ -662,7 +662,7 @@ class FormHelper extends AppHelper {
function hidden($fieldName, $options = array()) {
$options = $this->__initInputField($fieldName, $options);
$model = $this->model();
unset($options['class']);
if(isset($this->params['_Token']) && !empty($this->params['_Token'])) {
$model = '_' . $model;
}
@ -788,12 +788,12 @@ class FormHelper extends AppHelper {
function select($fieldName, $options = array(), $selected = null, $attributes = array(), $showEmpty = '') {
$showParents = false;
$escapeOptions = true;
if (isset($attributes['escape'])) {
$escapeOptions = $attributes['escape'];
unset($attributes['escape']);
}
$this->setFormTag($fieldName);
$this->__secure();
$attributes = $this->domId((array)$attributes);
@ -1078,7 +1078,7 @@ class FormHelper extends AppHelper {
*/
function __selectOptions($elements = array(), $selected = null, $parents = array(), $showParents = null, $attributes = array()) {
$attributes = am(array('escape' => true), $attributes);
$select = array();
foreach($elements as $name => $title) {
$htmlOptions = array();

View file

@ -538,7 +538,7 @@ class FormHelperTest extends CakeTestCase {
$this->assertNoPattern('/option value="other"\s+selected="selected"/', $result);
$this->assertNoPattern('/<select[^<>]+[^name|id]=[^<>]*>/', $result);
$this->assertNoPattern('/<option[^<>]+[^value|selected]=[^<>]*>/', $result);
$this->Form->data = array();
$result = $this->Form->select('Model/field', array('value' => 'good', 'other' => 'bad'));
$this->assertPattern('/option value=""/', $result);
@ -548,7 +548,7 @@ class FormHelperTest extends CakeTestCase {
$this->assertPattern('/<\/option>\s+<\/select>/', $result);
$this->assertNoPattern('/option value="field"\s+selected="selected"/', $result);
$this->assertNoPattern('/option value="other"\s+selected="selected"/', $result);
$result = $this->Form->select('Model/field', array('first' => 'first "html" <chars>', 'second' => 'value'), null, array(), false);
$this->assertPattern('/' .
'<select[^>]*>\s+' .
@ -556,7 +556,7 @@ class FormHelperTest extends CakeTestCase {
'<option\s+value="second"[^>]*>value<\/option>\s+'.
'<\/select>'.
'/i', $result);
$result = $this->Form->select('Model/field', array('first' => 'first "html" <chars>', 'second' => 'value'), null, array('escape' => false), false);
$this->assertPattern('/' .
'<select[^>]*>\s+' .
@ -608,7 +608,7 @@ class FormHelperTest extends CakeTestCase {
$this->assertPattern('/^<input[^<>]+type="hidden"[^<>]+\/>$/', $result);
$this->assertPattern('/^<input[^<>]+name="data\[Model\]\[field\]"[^<>]+id="theID"[^<>]+value="test"[^<>]+\/>$/', $result);
$this->assertNoPattern('/^<input[^<>]+name="[^<>]+name="[^<>]+\/>$/', $result);
$this->assertNoPattern('/<input[^<>]+[^type|name|id|value]=[^<>]*>/', $result);
$this->assertNoPattern('/<input[^<>]+[^type|name|id|value|class]=[^<>]*>/', $result);
}
function testFileUploadField() {
@ -665,57 +665,57 @@ class FormHelperTest extends CakeTestCase {
$result = $this->Form->create('Contact', array('id' => 'TestId'));
$this->assertPattern('/id="TestId"/', $result);
}
function testFormMagicInput() {
$result = $this->Form->create('Contact');
$this->assertPattern('/^<form\s+id="ContactAddForm"\s+method="post"\s+action="\/contacts\/add\/"\s*>$/', $result);
$result = $this->Form->input('Contact.name');
$this->assertPattern('/^<div class="input">' .
'<label for="ContactName">Name<\/label>' .
'<input name="data\[Contact\]\[name\]" type="text" maxlength="255" value="" id="ContactName" \/>'.
'<\/div>$/', $result);
$result = $this->Form->input('Contact.name', array('div' => false));
$this->assertPattern('/^<label for="ContactName">Name<\/label>' .
'<input name="data\[Contact\]\[name\]" type="text" maxlength="255" value="" id="ContactName" \/>$/', $result);
$result = $this->Form->input('Contact.non_existing');
$this->assertPattern('/^<div class="input">' .
'<label for="ContactNonExisting">Non Existing<\/label>' .
'<input name="data\[Contact\]\[non_existing\]" type="text" value="" id="ContactNonExisting" \/>'.
'<\/div>$/', $result);
$result = $this->Form->input('Contact.published', array('div' => false));
$this->assertPattern('/^<label for="ContactPublishedMonth">Published<\/label>' .
'<select name="data\[Contact\]\[published_month\]"\s+id="ContactPublishedMonth">/', $result);
$result = $this->Form->input('Contact.updated', array('div' => false));
$this->assertPattern('/^<label for="ContactUpdatedMonth">Updated<\/label>' .
'<select name="data\[Contact\]\[updated_month\]"\s+id="ContactUpdatedMonth">/', $result);
}
function testFormMagicInputLabel() {
$result = $this->Form->create('Contact');
$this->assertPattern('/^<form\s+id="ContactAddForm"\s+method="post"\s+action="\/contacts\/add\/"\s*>$/', $result);
$result = $this->Form->input('Contact.name', array('div' => false, 'label' => false));
$this->assertPattern('/^<input name="data\[Contact\]\[name\]" type="text" maxlength="255" value="" id="ContactName" \/>$/', $result);
$result = $this->Form->input('Contact.name', array('div' => false, 'label' => 'My label'));
$this->assertPattern('/^<label for="ContactName">My label<\/label>' .
'<input name="data\[Contact\]\[name\]" type="text" maxlength="255" value="" id="ContactName" \/>$/', $result);
$result = $this->Form->input('Contact.name', array('div' => false, 'label' => array('class' => 'mandatory')));
$this->assertPattern('/^<label for="ContactName" class="mandatory">Name<\/label>' .
'<input name="data\[Contact\]\[name\]" type="text" maxlength="255" value="" id="ContactName" \/>$/', $result);
$result = $this->Form->input('Contact.name', array('div' => false, 'label' => array('class' => 'mandatory', 'text' => 'My label')));
$this->assertPattern('/^<label for="ContactName" class="mandatory">My label<\/label>' .
'<input name="data\[Contact\]\[name\]" type="text" maxlength="255" value="" id="ContactName" \/>$/', $result);
$result = $this->Form->input('Contact.name', array('div' => false, 'id' => 'my_id', 'label' => array('for' => 'my_id')));
$this->assertPattern('/^<label for="my_id">Name<\/label>' .
'<input name="data\[Contact\]\[name\]" type="text" id="my_id" maxlength="255" value="" \/>$/', $result);
@ -723,7 +723,7 @@ class FormHelperTest extends CakeTestCase {
function testFormEnd() {
$this->assertEqual($this->Form->end(), '</form>');
$result = $this->Form->end(array('submit' => 'save'));
$this->assertEqual($result, '<div class="submit"><input type="submit" value="save" /></div></form>');
}