Zend_Form decorators ordering (Errors before form element issue) - zend-form

I have the following Zend_Form code to apply to form element decorators:
$decorators = array(
'ViewHelper',
'Description',
array('break' => 'HtmlTag', array('tag' => 'br', 'openOnly'=>true)),
array('Label', array('class' => 'formLabel', 'separator'=>' ', 'requiredSuffix' => ' <em class="requiredFormElement">(requried)</em>', 'escape'=>false)),
array('Errors', array('class' => 'formErrors')),
array(array('row' => 'HtmlTag'), array('tag' => 'div')),
);
It seems no matter what I do I can't seem to make the Errors show up before the form element (and label) itself. Am I missing something? Everything else seems to be ordered correctly. Can this only be done with a custom decorator?
Thank you in advance.

Try the following, don't know if it'll work, since I don't have my laptop at the moment:
array('Errors', array('class' => 'formErrors', 'placement' => 'prepend'))

Related

CJuiDatePicker in yii is not working

In my web application, I want to implement a date field. For this i am using CJuiDatePicker. But for me it not showing calendar.
My code is,
$this->widget('zii.widgets.jui.CJuiDatePicker', array(
'name' => 'Employee[employee_joiningdate]',
'id' => 'Employee_employee_joiningdate',
'value' => Yii::app()->dateFormatter->format("d-M-y", strtotime($model->employee_joiningdate)),
'options' => array(`
'showAnim' => 'slide', //'slide','fold','slideDown','fadeIn','blind','bounce','clip','drop'
'showOtherMonths' => true, // Show Other month in jquery
'selectOtherMonths' => true, // Select Other month in jquery
),
'htmlOptions' => array(
'class' => 'form-control'
),
));`
What i am doing wrong?
Please help me....
Thanks in advance.

How to create a ZF2 FormCollection of the Doctrine ORM Module's ObjectSelect elements?

I have an odd situation where my add form works perfectly, but the edit form will not even load. Instead I get the following error:
Notice: Undefined property: DoctrineModule\Form\Element\ObjectSelect::$object in /vendor/zendframework/zendframework/library/Zend/Form/Element/Collection.php on line 517
Fatal error: Class name must be a valid object or a string in /vendor/zendframework/zendframework/library/Zend/Form/Element/Collection.php on line 517
I have objects of the class Application\Model\Record which have a many-to-many relationship to objects of the class Application\Model\Subject. I want the Subjects to appear as dropdowns in the Record forms, with the option to add multiple Subjects. So in the RecordFieldset.php I have:
$this->add(array(
'name' => 'subjects',
'type' => 'Zend\Form\Element\Collection',
'options' => array(
'label' => 'Subjects',
'count' => 1,
'should_create_template' => true,
'allow_add' => true,
'allow_remove' => true,
'template_placeholder' => '__subjectindex__',
'target_element' => array (
'name' => 'subject',
'type' => 'DoctrineModule\Form\Element\ObjectSelect',
'options' => array(
'object_manager' => $this->objectManager,
'target_class' => 'Application\Model\Subject',
'property' => 'name',
'empty_option' => 'Select a subject',
),
'attributes' => array(
'class' => 'form-control',
),
),
),
));
And like I said, this works perfectly in the Record add form. But it looks like on the edit form it cannot load the Subjects. Has anyone else tried something like this? Or do you have an idea what the error is saying?
Environment:
Zend Framework 2.3.3
Doctrine-orm-module 0.8.0
Doctrine 2.4.2
Looks like this is a bug on ZF2, target elements need to be a fieldset for it to work otherwise it will run into this issue. Use a fieldset to wrap the ObjectSelect.

Decorators for Zend_Dojo_Form

I have a Zend_Dojo_Form and like to change the decorator for it:
//inside my Zend_Dojo_Form
$this->setDecorators(array(
'FormElements',
'DijitForm',
array(array('tr' => 'HtmlTag'), array('tag' => 'tr')),
array(array('table' => 'HtmlTag'), array('tag' => 'table')),
));
The rendered form looks fine but if I submit only Zend_Form_Elements, but no Zend_Dojo_Form_Elements are POSTed. If I do not change the decorators, all values are submitted, but the layout is (of course) broken. Do I miss some essential decorator?
The problem turned out to be more html than zend related
$this->setDecorators(array(
'FormElements',
array(array('tr' => 'HtmlTag'), array('tag' => 'tr')),
array(array('table' => 'HtmlTag'), array('tag' => 'table')),
'DijitForm',
));
works, because now the form elements spans the whole table.

Yii CListView summary text

Is there any way to hide "Summary" for CListView without loosing pagination. By summary i mean text like "Displaying 1-2 of 2 result(s).". Or maybe I should use different widget?
Try the following to get more control over the look of your CListView output:
'template'=>'{items} {pager}'
You can even use HTML in the template.
Ok, I didn't get it at first, when looking into CListView code, but setting 'summaryText' to '' will do the work. I've realised that second time when I was staring at $summaryText === null
$this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'summaryText'=>'',
'itemView'=>'_indexview',
));
Here is the example for CListView:
$this->widget('zii.widgets.CListView', array(
'dataProvider' => $dataProvider,
'itemView' => '_view',
'ajaxUpdate' => false,
'emptyText' => 'No records found.',
'summaryText' => "{start} - {end} из {count}",
'template' => '{summary} {sorter} {items} {pager}',
'sorterHeader' => 'Sort by:',
'sortableAttributes' => array('title', 'price'),
'pager' => array(
'class' => 'CLinkPager',
'header' => false,
'cssFile' => '/css/pager.css',
'htmlOptions' => array('class' => 'pager'),
'maxButtonCount' => '10',
'prevPageLabel'=>'←',
'nextPageLabel'=>'→',
'header'=>'Pages: ',
),
));
You should try this:
'summaryText' => FALSE,
You may hide it by adding CSS in the page like below.
<style>
.summary{
display:none;
}
</style>
Here is my suggestion
$this->widget('zii.widgets.CListView', array(
'dataProvider' => $best_seller_data,
'itemView' => 'alsoBestseller',
'summaryText'=>false,
));

Error with dijit.form.NumberTextBox

Despite many trials and errors, I cannot get the NumberTextBox widget to work. I keep receiving this error message:
Catchable fatal error: Argument 4 passed to Zend_Dojo_View_Helper_NumberTextBox::numberTextBox() must be an array, null given
The odd thing is: I event tried this example straight from the ZF examples page and it failed with the same error
->addElement(
'NumberTextBox',
'numberbox',
array(
'label' => 'NumberTextBox',
'required' => true,
'invalidMessage' => 'Invalid elevation.',
'constraints' => array(
'min' => -20000,
'max' => 20000,
'places' => 0,
)
)
)
So, I'm at a loss now. If someone has the time to look at the code found here, your help would be greatly appreciated. I know it's something that I'm overlooking. It always is.
If you are setting decorators, make sure you change ViewHelper to DijitElement. I ran into this problem and that was the cause.
Shot in the dark: try getting rid of the ',' at the end of 'places' => 0,'
I use a base Form,
BaseForm extends Zend_Dojo_Form{
public $elementDecorators = array(
'DijitElement',
array(
array('data' => 'HtmlTag'),
array('tag' => 'div', 'class' => 'element')
),
array('Label',
array('tag' => 'div', 'class' => 'element-label')
),
array(array('row' => 'HtmlTag'),
array('tag' => 'div', 'class' => 'element-row' )
)
);
... init(){}
.... construct(){}
}
MyForm extends BaseForm{
constructor(){
$this->starts = new Zend_Dojo_Form_Element_DateTextBox( "starts" );
$this->starts->setLabel('Starting from')
->setDecorators($this->elementDecorators);
}
}
I made the source code as simple as possible, to depict the idea of what I mean.