ZF-10450: Zend_Form: Prepending empty elements like <br /> with standards decorators
Description
I want prepend
to an form element. I use the following decorator:
protected $_elementDecorators = array( 'ViewHelper', 'Description', 'Errors', array(array('LineBreak' => 'HtmlTag'), array('tag' => 'br', 'placement' => 'prepend')), 'Label', array('HtmlTag', array('tag' => 'div', 'class' => 'zend_element')), );
The result of the LineBreak decoration is "
", but with options like "openOnly" it is invalid XHTML. It seems where is no way to place an empty tag like
with help of the standard decorators to the form.
Comments
Posted by Guy Halford-Thompson (guyht) on 2011-01-20T05:33:37.000+0000
Zend_Form_Decorator_HtmlTag does not appear to support these types of tags.
The decorator allows for openOnly and closeOnly but not for tags that require /> at the end. This would also be the case for
.
Since there are only a small number of tags that are affected by this (
,
, others?) then I propose that the Zend_Form_Decorator_HtmlTag is adapted to recognise these tags and render them as . Note: tags will not be handled by Zend_Form_Decorator_HtmlTag as they have their own classes.
The alternative would be to add another optional argument to Zend_Form_Decorator_HtmlTag, 'singleTag', which would render the tag with /> at the end.
I would like to work on this issue but I think we need some additional input before I start as to which of the above resolutions would be best.
G
Posted by Kai Uwe (kaiuwe) on 2011-01-20T06:37:57.000+0000
@Andreas Please use always the code tags and show us the desired output.
Here is a workaround: (very simple with PHP 5.3)
"Callback" is a standard decorator!
Posted by Guy Halford-Thompson (guyht) on 2011-01-23T13:03:23.000+0000
Have added a patch.
A new option is available, 'selfClosing'. This option requires a placement to be set as you cannot have content within a self closing tag. Throws a Zend_Form_Decorator_Exception if no placement set.
Guy
Posted by Kai Uwe (kaiuwe) on 2011-01-24T05:25:43.000+0000
This is a bad idea:
XHTML vs. HTML!
Posted by Guy Halford-Thompson (guyht) on 2011-01-24T05:42:52.000+0000
What would you suggest as a solution? Shouldnt the framework be XHTML compliant?
Posted by Kai Uwe (kaiuwe) on 2011-01-24T05:52:54.000+0000
Both: HTML and XHTML!
Posted by Guy Halford-Thompson (guyht) on 2011-01-24T05:58:32.000+0000
Ok, will amend code and tests and resubmit the patch. G
Posted by Guy Halford-Thompson (guyht) on 2011-01-26T14:52:17.000+0000
I have updated the patch to differentiate between HTML and XHTML. I have also split the patch into two files (tests and library).
Please could someone review the patches.
Thanks
G
Posted by Timmo Henseler (zensys) on 2011-06-22T09:38:12.000+0000
@Guy Halford-Thompson Is this patch operational yet? If so could you provide a usage example please?
I use:
->addDecorator('HtmlTag', array('tag' => 'br', 'placement' => 'prepend', 'selfClosing' => true))
but that gives me:
....
thanks, T
Posted by Kai Uwe (kaiuwe) on 2011-06-22T09:57:00.000+0000
Hi Timmo, have you add the patch to your local library?