I have been searching for this from a long time but couldnt find a good article. I am using the following code-
$this->addElement('Text', 'to',array( 'label'=>'My Text Box'));
$this->addElement('checkbox',
'my checkbox',
array( 'label'=>'',
'decorators' => array(
array('Label', array('placement' => 'PREPEND')),
array('ViewHelper') ) )
);
Instead the check box comes a line after the text box. Thanks in Advance!
You should use 'APPEND' instead of 'PREPEND' if you want your label after your checkbox
Related
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 use framework YII. I will do link for e-mail in my list from GRID. I added this:
array(
'class'=>'CLinkColumn',
'header'=>'e-mail',
'labelExpression'=>'$data->email',
'urlExpression'=>'"mailto:".$data->email',
),
this working ok, but now i dont hava column filter. CLinkColumns doesnt has method filter. How can i make link mailto: and use filter for this?
You could also try something like this:
array(
'name' => 'email',
'header' => 'e-mail',
'type' => 'raw',
'value' => 'CHtml::link($data->email,"mailto:".$data->email)'
),
You can't use a filter with CLinkColumn.
The Yii developers discussed adding 'name' to CLinkColumn here: https://github.com/yiisoft/yii/pull/970
They decided against it:
... there is no need to "complicate" [CLinkColumn] further as that would be just a duplication of code or "hacks" to solve issues...
samdark says:
CLinkColumn will be there for simple usage only . If you need more options, consider using value.
This is their recommended alternative:
array(
'name' => 'field_name',
'type' => 'raw',
'value' => 'CHtml::link($data->field_name,$data->field_name)'
),
give it a shot like this --
array(
'class'=>'CLinkColumn',
'header'=>'e-mail',
'labelExpression'=>'$data["email"]',
'urlExpression'=>'"mailto:".$data["email"]',
),
I have a form same the following code:
public function init(){
$id=$this->createElement('hidden','cf_id');
$id->setDecorators($this->elementDecorators);
$id->setOrder(1);
$this->addElement($id);
$firstName=$this->createElement('text','firstName');
$firstName->setDecorators($this->elementDecorators);
$firstName->setLabel('name :');
$firstName->setOrder(2);
$firstName->setAttrib('class','textbox');
$firstName->setAttrib('disabled',true);
$this->addElement($firstName);
$lastname=$this->createElement('text','family');
$lastname->setLabel(' family:');
$lastname->setDecorators($this->elementDecorators);
$lastname->setOrder(3);
$lastname->setAttrib('class','textbox');
$lastname->setAttrib('disabled',true);
$this->addElement($lastname);
$this->addElement('button', 'cancel', array(
'label' => 'Cancel Button',
'class'=>'button',
'decorators' => array(
'ViewHelper',
),
));
$this->addElement('button', 'submit', array(
'label' => 'Submit Button',
'class'=>'button',
'decorators' => array(
'ViewHelper',
),
));
$this->addDisplayGroup(array('submit', 'cancel',), 'submitButtons', array(
'order'=>4,
'decorators' => array(
'FormElements',
array('HtmlTag', array('tag' => 'div', 'class' => 'element')),
),
));
}
In this form there are some elements and two buttons. In display page, the buttons are shown above form before other elements.
How can I put these buttons at the bottom of all elemnts?
Thanks.
Zend renders the elements in the order in which they are added via the addElements() method. So, I would add them like this:
$this->addElements(array(all elements you want to appear first in top-down order));
$this->addElements(array(button elements));
Then use CSS in the view to manipulate their locations.
Hope that helps.
add them before other elements ;-)
Add your other fields to another display group, defined before the display group you already have. You will probably need to adjust the decorators some-what.
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')
)
)
);
What I am trying to accomplish is to have checkbox labels display after checkbox input fields (to the right of them).
I am using these decorators now:
private $checkboxDecorators = array(
Label,
array(array('data' => 'HtmlTag'), array('tag' => 'div', 'class' => 'checkbox')),
'ViewHelper',
array(array('row' => 'HtmlTag'), array('tag' => 'li')),
);
I have tried switching the Label and ViewHelper decorators but that did nothing. Any suggestions?
$this->getElement('elementId')->addDecorator('Label', array('placement' => 'APPEND'))
the placement option can take APPEND or PREPEND as value
I know that is an older question, but you can also use
$element->getDecorator('label')->setOption('placement', 'APPEND');
if it is an already created element with an existing decorator