Issues

ZF-2989: DtDdWrapper is not xhtml valid

Description

The empty definition term which is placed using Zend_Form when no label is specified (for example a submit button) is not XHTML valid. Therefore I suggest that, if the doctype is set to XHTML, the wrapper either doesn't place the empty definition term

, or places a nonbraking space inside it  .

Comments

Please evaluate and categorize as necessary.

Scheduling for next mini release.

fixed in trunk and release-1.5 branch as of r9310.

The situation described is not invalid XHTML, and the non-breaking space should be removed again.

uhm... yes it is invalid..?

Where does it say it's valid? I am unable to find a source that backs up your statement, and according to the W3C validator the document is valid. You shouldn't just say "umh, yes it is invalid?" without backing it up.

http://www.w3.org/TR/xhtml1/ http://w3.org/TR/1999/… http://www.w3schools.com/tags/tag_dt.asp

Also, the reason I'm complaining is this: With an empty

, the element is not rendered, and the ... below will position itself where the dt element would be, whereas with   the dt element renders and takes up visual space on the page. This means that by default you get a notable gap between the last form element and the submit button, which looks odd (it looks like the form is missing something), and if you care about visual design you have to turn to various hacks to "remove the gap". Far from ideal.
foobar!

The attached file passes W3C validation.

Tip: Copy-paste the file contents into this: http://validator.w3.org//…

Sounds good, Matthew :)

The empty definition term tag issue is probably caused from using HTML Tidy to validate, e.g running the above snippet through Tidy will show the following as an error:

 trimming empty 
{/noformat} Tested using: [http://validator.aborla.net] In this regard Tidy is a bit over keen, it shouldn't be throwing errors for things that are perfectly valid. In fact HTML Tidy shouldn't really be used as a validator, unfortunately it is used by certain Firefox HTML validator plugins for this purpose. Matthews suggestion of providing a switch to the DtDdWrapper asking to insert a non-breaking space is a good solution. As well as a non-breaking space could an option to put empty comment tags be added, e.g:

{/noformat}

This works around the HTML Tidy issue without adding whitespace into the rendered HTML page, the non-breaking space will increase or decrease in size depending on the font size.

The issue clearly wasn't fixed with 1.5.2 (else the issue would have been closed?) so could someone please give it a new fix version, or postpone it?

Setting fix version to unknown. The 1.5.2 fix version was regarding the original fix (adding the no-break space).

made a patch for converting   to   after that i detected this Issue, so i merged the other into this one. The patch is easy converted to take instead.

Because i think the argument weights, that adding whitespace into rendered html is bad, here the updated patch from SubTask


Index: tests/Zend/Form/SubFormTest.php
===================================================================
--- tests/Zend/Form/SubFormTest.php     (Revision 21740)
+++ tests/Zend/Form/SubFormTest.php     (Arbeitskopie)
@@ -130,7 +130,7 @@
         $form->addSubForm($subForm, 'foobar')
              ->setView(new Zend_View);
         $html = $form->render();
-        $this->assertContains(' ', $html);
+        $this->assertContains('', $html);
     }
 }
 
Index: tests/Zend/Form/DisplayGroupTest.php
===================================================================
--- tests/Zend/Form/DisplayGroupTest.php        (Revision 21740)
+++ tests/Zend/Form/DisplayGroupTest.php        (Arbeitskopie)
@@ -401,7 +401,7 @@
 
         $this->group->addElements(array($foo, $bar));
         $html = $this->group->render($this->getView());
-        $this->assertRegexp('#^]*> ]*>$#s', $html, $html);
+        $this->assertRegexp('#^]*>]*>$#s', $html, $html);
         $this->assertContains('assertContains('"foo"', $html);
         $this->assertContains('"bar"', $html);
@@ -415,7 +415,7 @@
         $this->group->addElements(array($foo, $bar))
                     ->setView($this->getView());
         $html = $this->group->__toString();
-        $this->assertRegexp('#^]*> ]*>$#s', $html, $html);
+        $this->assertRegexp('#^]*>]*>$#s', $html, $html);
         $this->assertContains('assertContains('"foo"', $html);
         $this->assertContains('"bar"', $html);
Index: tests/Zend/Form/Element/RadioTest.php
===================================================================
--- tests/Zend/Form/Element/RadioTest.php       (Revision 21740)
+++ tests/Zend/Form/Element/RadioTest.php       (Arbeitskopie)
@@ -168,7 +168,7 @@
                 'test' => 'Test',
             ));
         $html = $this->element->render($this->getView());
-        $this->assertRegexp('#]*> .*?assertRegexp('#]*>.*?render();
 
-        $this->assertContains(' ', $html);
+        $this->assertContains('', $html);
         $this->assertContains('', $html);
     }
 
@@ -3773,7 +3773,7 @@
 
         $html = $form->render();
 
-        $this->assertContains(' ', $html);
+        $this->assertContains('', $html);
         $this->assertContains('', $html);
     }
 
Index: library/Zend/Form/Decorator/Label.php
===================================================================
--- library/Zend/Form/Decorator/Label.php       (Revision 21740)
+++ library/Zend/Form/Decorator/Label.php       (Arbeitskopie)
@@ -310,7 +310,7 @@
             $options['class'] = $class;
             $label = $view->formLabel($element->getFullyQualifiedName(), trim($label), $options);
         } else {
-            $label = ' ';
+            $label = '';
         }
 
         if (null !== $tag) {
Index: library/Zend/Form/Decorator/DtDdWrapper.php
===================================================================
--- library/Zend/Form/Decorator/DtDdWrapper.php (Revision 21740)
+++ library/Zend/Form/Decorator/DtDdWrapper.php (Arbeitskopie)
@@ -57,7 +57,7 @@
     {
         $elementName = $this->getElement()->getName();
 
-        return ' ' .
+        return '' .
                '' . $content . '';
     }
 }

Rescheduling for next Minor Release as the workarounds for the whitespace must be adapted by Developers.

Fixed in trunk r22128 and merged into 1.10 release branch.

DtDdWrapper retrieves the filler for the label now from option 'dtLabel', if this is not set defaults to ' ' //edit: stupid whitespace


public function render($content)
    {
        $elementName = $this->getElement()->getName();
        
        $dtLabel = $this->getOption('dtLabel');
        if( null === $dtLabel ) {
            $dtLabel = ' ';
        }

        return '' . $dtLabel . '' .
               '' . $content . '';
    }