List Info

Thread: Zend_Form setting element decorators with Zend_Config_Xml




Zend_Form setting element decorators with Zend_Config_Xml
user name
2008-05-08 02:52:41
Hi,

when I set element decorators with the setDecorators()
method using an
array I get a different output than doing the same with a
Zend_Config_Xml object.

------------------------------------------------------------
----------
Using:

$name->setDecorators(array(
        'ViewHelper',
        'Errors',
        array(array('data' => 'HtmlTag'),
              array('tag' => 'div', 'class' =>
'element')),
        array('Label', array('class' => 'left')),
        array(array('row' => 'HtmlTag'),
              array('tag' => 'div', 'class' =>
'row')),
    ));

produces output:

<div class="row">
<label for="name" class="left
required">Name</label>
<div class="element">
<input type="text" name="name"
id="name" value=""
size="40">
</div>
</div>

------------------------------------------------------------
----------
Using an xml file:

<name>
	<type>text</type>
	<options>
		<size>40</size>
		<maxlength>40</maxlength>
		<label>Name</label>
		<decorators>
			<viewhelper>
				<decorator>ViewHelper</decorator>
			</viewhelper>
			<errors>
				<decorator>Errors</decorator>
			</errors>
			<data>
				<decorator>HtmlTag</decorator>
				<options>
					<tag>div</tag>
					<class>element</class>
				</options>
			</data>
			<label>
				<decorator>Label</decorator>
				<options>
					<class>left</class>
				</options>
			</label>
			<row>
				<decorator>HtmlTag</decorator>
				<options>
					<tag>div</tag>
					<class>row</class>
				</options>
			</row>
		</decorators>
	</options>
</name>

produces output:

<label for="name" class="left
required">Name</label>
<div class="row">
<input type="text" name="name"
id="name" value=""
size="40">
</div>

------------------------------------------------------------
----------

It seems as if the declaration of the "row"
decorator overwrites the
declaration of the "data" decorator.

How do I need to declare the decorators in the xml file to
get the same
result as above?

Thanks and best regards,

Ralf


Re: Zend_Form setting element decorators with Zend_Config_Xml
user name
2008-05-08 04:20:40
Hi again,

ok, solved the issue myself:

<name>
	<type>text</type>
	<options>
		<size>40</size>
		<maxlength>40</maxlength>
		<label>Name</label>
		<decorators>
			<viewhelper>
				<decorator>ViewHelper</decorator>
			</viewhelper>
			<errors>
				<decorator>Errors</decorator>
			</errors>
			<data>
				<decorator>
					<data>HtmlTag</data>
				</decorator>
				<options>
					<tag>div</tag>
					<class>element</class>
				</options>
			</data>
			<label>
				<decorator>Label</decorator>
				<options>
					<class>left</class>
				</options>
			</label>
			<row>
				<decorator>
					<row>HtmlTag</row>
				</decorator>
				<options>
					<tag>div</tag>
					<class>row</class>
				</options>
			</row>
		</decorators>
	</options>
</name>

Thanks anyway,

Ralf

Zend_Form_Element Metadata & Attributes
user name
2008-05-08 05:51:02
Hi All,

Fiddling around with Zend_Form_Element and extending it I
created a 
F500_Form_Element_File (temporary, untill Zend one finally
comes 
around...). I also added a decorator called
"Progress" to automatically 
add the needed HTML for an upload  progress bar, but in
doing so I need 
some extra parameters - which automatically end up in the
<input 
type="file"> tag...

<input type="file" name="upload"
id="upload" value=""
class="large" 
formid="fileupload" statustemplate="status
template # of 
#: #%">

I found the following in the manual:
"By default, all attributes are passed to the view
helper used by the 
element during rendering, and rendered as HTML attributes of
the element 
tag."

I also found an issue in the tracker already:
http:
//framework.zend.com/issues/browse/ZF-3052

Is there currently any way to avoid the attributes getting
set in the 
element tag?
(I have implemented it in the Progress decorator with a 
$_blacklistedAttributes for now but I wanted to ask if there
is a more 
"general" way...)

Kind regards,


Ramon

ps: for those interested - my code was based on an exellent
article I 
found regarding file uploads and progress bars: 
http://www.phpriot.com/articles/php-ajax-file-uploads
It depends on APC, and utilizes the prototype javascript
library...

[1-3]

about | contact  Other archives ( Real Estate discussion Medical topics )