Maybe somebody knows. How to wrap Zend_Form_Element_Radio including Label of whole stack of radio inputs (with input labels).
public $radioDecorators = array(
'ViewHelper',
array('Description',array('tag'=>'div','class'=>'','placement' => 'prepend')),
array('Errors',array('class'=>'error_message_show','placement' => 'prepend')),
array(array('data' => 'HtmlTag'), array('tag' => 'div', 'class' => 'element')),
array('label', array('class'=>'label_text','placement' => 'prepend')),
array(array('rows' => 'HtmlTag'), array('tag' => 'div', 'class' => 'radio')),
);
$offer_type = new Zend_Form_Element_Radio('offer_type', array(
'label' => 'Label I'd like to wrap with inputs', //Label to wrap
'required' => true,
'description' => '',
'decorators' => $this->radioDecorators,
'multioptions' => array (
'standard' => 'standard',
'premium' => 'premium',
),
));
$this->addElement($offer_type);
Above example didn's solve my as it wraps only several inputs label's.
I think I know what you're after and if so, you're in luck as I just had to do this the other day.
The standard ZF multi-option element separates each "option" using the separator property (defaults to <br /> for radio and newline for select). This is fine for <option> elements but pretty shoddy for a collection of radio buttons.
The solution is to
Add HtmlTag decorator(s) to the element, wrapping the content
Set the separator to close and re-open the HtmlTag
For example, here's a solution to wrap the collection of inputs in an unordered list
$offer_type = new Zend_Form_Element_Radio('offer_type', array(
'separator' => '</li><li>',
'decorators' => array(
'ViewHelper',
array(array('liWrapper' => 'HtmlTag'), array('tag' => 'li')),
array(array('ulWrapper' => 'HtmlTag'), array('tag' => 'ul')),
// the rest
)
));
The alternative is to write your own view helper. Creating your own version of formRadio should be pretty easy.
Related
Hi i am using zend i want to put some styling in specific label how can i
class Application_Form_CategoryEnablingItemsForm extends Zend_Form {
public $elementDecorators = array(
'ViewHelper',
'Errors',
array('Description', array('tag' => 'p', 'class' => 'description')),
array(array('row' => 'HtmlTag'), array('tag' => 'div', 'class' => 'col-md-4 displaycls')),
array('Label', array('class' => 'col-md-3 control-label displaylbl', 'requiredSuffix' => '*')),
array('Errors', array('class' => 'zend-error'))
);
$this->addElement('select', 'product_category_parent', array(
'label' => 'Product Category Parent Name',
'required' => true,
'multiOptions' => $productCategory_options,
'filters' => array('StringTrim'),
'class' => 'form-control selection parent_category',
));
$productCategory_sub = $productCategoryMapper->getAllProductCategory();
$productCategory_sub_options = array();
$productCategory_sub_options[""]= "-Product Sub Category Name-";
if($productCategory_sub)
{
foreach ($productCategory_sub as $category)
{
$productCategory_sub_options[$category->product_category_id] = $category->product_category_name;
}
}
I added 'attribs' => array ('style' => 'margin-left: -799px; ')
but its working for whole select options not working for label,Any suggestions?
Try below code and just add your lable style class in place of my-class-name class.
$element = $this->createElement("select", 'product_category_parent');
$element->setLabel('Product Category Parent Name');
$element->setRequired(TRUE);
$element->addMultiOptions($productCategory_options);
$element->setAttrib("class", 'form-control selection parent_category');
$element->removeDecorator('HtmlTag');
$element->setDecorators(array('ViewHelper'));
$element->getDecorator('Label')->setOption('class', 'my-class-name');
I have a zend form with some element on, including a check box.
It looks normal :
checkbox label []
I would like to add a link to the right making it look like this:
checkbox label [] thelink
I've tried the following, but instead of aligning horizontaly the description with the checkbox it puts it under it :
$boolean->setDescription('desc');
$boolean->setDecorators(array(
'ViewHelper',
'Description',
'Errors',
array('HtmlTag', array('tag' => 'dd')),
array('Label', array('tag' => 'dt')),
));
I'm a begginer with Zend Forms. Any idea how could i implement this?
Thank you
Got it!
Here's how i did it:
$boolean->setDescription('description');
$boolean->setDecorators(array(
'ViewHelper',
'Description',
'Errors',
array('HtmlTag', array('tag' => 'dd')),
array('Label', array('tag' => 'dt')),
array('Description', array('escape' => false, 'tag' => '', 'placement' => 'append')),
));
For example:
$assignment_type = $this->createMyElement('text', 'assignment_type', array(
'name' => 'assignment_type',
'id' => 'assignment_type_label'
))->setAttrib('maxlength', '100')->addDecorator('Htmltag', array('tag' => 'div', 'class' => 'input_text'));
Here I am creating an input wraped by div tag, but how can I add other element inside this div?
So I want to see something like this:
<div>
<input />
<img /> <!--the brother element created -->
</div>
Is that possible? or what hacks I need to use?
Here's how I did it to wrap three elements in one div (a date picker in this case):
$bday = new Zend_Form_Element_Select('bday');
$bday->setLabel('Birth Date: ')
->setDecorators(array(
array('ViewHelper'),
array('Label', array('tag' => 'dt')),
array('HtmlTag', //opening tag
array(
'tag' => 'div',
'openOnly' => TRUE,
'id' => 'bday',
'placement' => 'prepend'
)),
));
$bdaymonth = new Zend_Form_Element_Select('bdaymonth');
$bdaymonth->addValidator('Digits')
->setDecorators(array(
array('ViewHelper')
));
$bdayyear = new Zend_Form_Element_Select('bdayyear');
$bdayyear->addValidator('Digits')
->setDecorators(array(
array('ViewHelper'),
array('HtmlTag', //closing tag
array(
'tag' => 'div',
'closeOnly' => TRUE
)),
)); //elements truncated for brevity
I hope this gives you some ideas.
I'm using ZendFramework 1.11 and Zfdatagrid 0.8.
I've created a grid and a CRUD-form using my own db-model as source. Then I added some extra elements to the CRUD-form like this:
$element = new Zend_Form_Element('element', array('label'=>'new element:'));
$grid->getForm(1)->addElement($element);
The new element is added to the form properly, but whereas all other form elements are within a table, the added element is placed as a list element above the actual form. Instead of this, i would like to have the added element as a part of the table to achieve a proper look of the form. Has anybody faced this issue before or an idea of how to do it? Any help is appreciated!
Thanks in advance!
$elementDecorators = array(
'ViewHelper',
'Errors',
array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class' => 'element')),
array('Label', array('tag' => 'td', 'class' => 'form_label')),
array(array('row' => 'HtmlTag'), array('tag' => 'tr')),
);
$this->_grid->getForm(1)->addElement('select', 'group', array(
'required' => true,
'value' => 'rtrt',
'label' => 'Group',
'multiOptions' => $list_contactgroup,
'order' => 5, 'decorators' => $elementDecorators
));
I need to decorate to Zend_Form_Element_MultiCheckbox into a unordered list, I can get each item surround by <li>, by setting setSeparator to </li><li> and the HtmlTag tag to <li>
I just get find anything to set the <ul> around this list, anyone able to point me in the right direction?
Thanks for reading (My code is below)
$interests = new Zend_Form_Element_MultiCheckbox('foo');
$interests->setSeparator('</li><li>');
foreach ($interestsTable->findForSelect() as $interest) { // For earch interest add an option
$interests->addMultiOption($interest->interest_id, $interest->interest);
}
// Decorate the interests
$interests->setDecorators(array(
array('ViewHelper'),
array('label', array(
'tag' => 'span' )),
array('HtmlTag', array(
'tag' => 'li', 'class' => 'interestOption'))
));
I can't give you any code that will work off the top of my head, but, from reading the docs, it's clear that you can re-use decorators as many times as you need to. You just need to specify a new name for them.
Look at: http://framework.zend.com/manual/en/zend.form.elements.html#zend.form.elements.decorators, specifically the section titled "Using Multiple Decorators of the Same Type".
Based on that, the below might work (but I haven't tested it, it could be in the wrong order or anything):
$interests->setDecorators(
array(
array('ViewHelper'),
array('label', array( 'tag' => 'span' )),
array('HtmlTag', array( 'tag' => 'li', 'class' => 'interestOption')),
array(
'decorator' => array('LiTag' => 'HtmlTag'),
'options' => array('tag' => 'ul')
)
)
);