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.
Related
I'm new to Yii framework. Currently I have three models test1,test2,test3. I created admin pages for all the three models. So I can view gridview for each model individually.
Now , I want to use single page for all the three gridview. i.e I want to create three tabs in that page. Each tab should open a gridview of that corresponding model name.
How can I do this.
I'v passed $model and $form which is my active form to each tab by rendering it partially,
put your grids in 'view/_form_firstPart' and 'view/_form_second'
$this->widget('bootstrap.widgets.TbTabs', array(
'id' => 'tabs',
'type' => 'tabs', // '', 'tabs', 'pills' (or 'list')
'tabs' => array(
array(
'label' => 'someLabel',
'content' => $this->renderPartial('_form_firstPart', array(
'model' => $model,
'form' => $form,
)
,true),
'active' => true,
),
array(
'label' => 'anotherLabel',
'content' => $this->renderPartial('_form_second', array(
'model' => $model,
'form' => $form,
) ,true),
),
)));
If you are not using bootstrap,than you can use cjuitabs,
$this->widget('zii.widgets.jui.CJuiTabs', array(
'tabs'=>array(
'first model' =>array('content'=>$tab_1),
'second model' =>array('content'=>$tab_2),
),
// additional javascript options for the tabs plugin
'options'=>array(
'collapsible'=>true,
),
));
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
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
));
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.
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')
)
)
);