Skip to content
This repository has been archived by the owner on Jan 8, 2020. It is now read-only.

<span>$label</span> only when filled #2290

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions library/Zend/Form/View/Helper/FormRow.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,13 +121,17 @@ public function render(ElementInterface $element)
$labelClose = $labelHelper->closeTag();
}

if ($label !== '') {
$label = '<span>' . $label . '</span>';
}

switch ($this->labelPosition) {
case self::LABEL_PREPEND:
$markup = $labelOpen . '<span>' . $label . '</span>' . $elementString . $labelClose;
$markup = $labelOpen . $label . $elementString . $labelClose;
break;
case self::LABEL_APPEND:
default:
$markup = $labelOpen . $elementString . '<span>' . $label . '</span>' . $labelClose;
$markup = $labelOpen . $elementString . $label . $labelClose;
break;
}

Expand Down
16 changes: 16 additions & 0 deletions tests/ZendTest/Form/View/Helper/FormRowTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,4 +257,20 @@ public function testSetLabelAttributes()
$this->helper->setLabelAttributes(array('foo', 'bar'));
$this->assertEquals(array(0 => 'foo', 1 => 'bar'), $this->helper->getLabelAttributes());
}

public function testWhenUsingIdAndLabelBecomesEmptyRemoveSpan()
{
$element = new Element('foo');
$element->setLabel('The value for foo:');

$markup = $this->helper->__invoke($element);
$this->assertContains('<span', $markup);
$this->assertContains('</span>', $markup);

$element->setAttribute('id', 'foo');

$markup = $this->helper->__invoke($element);
$this->assertNotContains('<span', $markup);
$this->assertNotContains('</span>', $markup);
}
}