Zend Form Decorators customization - zend-form

I was implementing the zend decorators like below:
$formDecorators = array(
'FormElements',
array( 'HtmlTag', array('tag' => 'dl',
'class' => 'survey_form')),
'Form',
);
$elementDecorators = array(
'ViewHelper',
'Errors',
array('HtmlTag', array('tag' => 'dd',
'class' => 'survey_form_dd')),
array('Label', array('tag' => 'dt',
'class' => 'survey_form_label name')),
);
generating like:
<dl>
<dt>
<dd class="survey_form_dd">
<label style="white-space: nowrap;">
Now, I want to add class to <dd> --> <Label> & also want to customize my decorators as per TABLE Structure.

Related

How do I set customized placeholder in 'booster.widgets.TbActiveForm'?

I use like this..
<div class="row">
<?php echo $form->textFieldGroup(
$User,'email_address',
array(
'wrapperHtmlOptions' => array(
'class'=> 'col-sm-5',
),
)
);
?>
</div>
But there is default placeholder 'Email Address'. How I want to set there my own placeholder ?
you can add html options as below:
<?php echo $form->textFieldGroup(
$User,'email_address',
array(
'wrapperHtmlOptions' => array(
'class'=> 'col-sm-5',
),
'widgetOptions' => array(
'htmlOptions' => array(
'placeholder' => 'my placeholder'
)
)
)
);
?>
for more detail have a look at Booster active form

yii CListView relation sorting

Currently when i click on sort by in CListView generated table, it adds MODEL_NAME_2 to the url
?page=1&sort=MODEL_NAME_2.cat.desc
is there a way to remove it? or maybe rename it to something else? Or is this just how Yii works?
here is my actionIndex() in my controller
public function actionIndex()
{
$dataProvider=new CActiveDataProvider('MODEL_NAME_1', array(
'id'=> '',
'criteria' => array(
'with' => 'MODEL_NAME_2',
'together'=>true, //specifies whether the query should be run using a join
),
'sort'=>array(
'defaultOrder'=>'MODEL_NAME_2.cat ASC',
'attributes'=>array(
'MODEL_NAME_2.cat'=>array(
'asc'=>'MODEL_NAME_2.cat',
'desc'=>'MODEL_NAME_2.cat DESC',
),
'*',
)
),
'pagination'=>array(
'pageVar'=>'page'
)
));
$this->render('index',array(
'dataProvider'=>$dataProvider,
));
}
in my view
$this->widget('zii.widgets.CListView', array(
'dataProvider'=>$dataProvider,
'itemView'=>'_view', // refers to the partial view named '_view'
'enableHistory'=> true,
'sortableAttributes' => array('MODEL_NAME_2.cat'=>'Make'),
'pagerCssClass' => 'pagination',
'loadingCssClass' => '', //remove loading icon
'template'=>'
<div class="row">
<div class="col-md-12">
<div class="pull-left">{summary}</div>
<div class="pull-right">{sorter}</div>
</div>
</div>
<div class="row">
<div class="col-md-12">{items}</div>
</div>',
));
ideally i would like my url to look like this
mysite.com/bla/page/2/sort/cat/desc
basically using alot of / and no ? or &
In ListView definition change:
'sortableAttributes' => array('make'=>'Make'),
In your dataProvider
'sort'=>array(
'defaultOrder'=>'MODEL_NAME_2.cat ASC',
'attributes'=>array(
'make'=>array(
'asc'=>'MODEL_NAME_2.cat',
'desc'=>'MODEL_NAME_2.cat DESC',
),
'*',
)
),

How to show timepicker based jqrelcopy yii?

How to show timepicker based yiibooster, with Jqrelcopy.
I've code like this :
<div class="control-group "><label class="control-label required">Jam Kerja</label>
<div class="controls">
<a id="copylink" href="#" rel=".copy">Tambah Jam Kerja / Shift</a>
<div class="row copy">
<?php echo CHtml::label('',''); ?>
<?php $this->widget('bootstrap.widgets.TbTimePicker',
array(
'name' => 'some_time',
'value' => '00:00',
'htmlOptions'=>array('width'=>'50px'),
'noAppend' => true, // mandatory
'options' => array(
'disableFocus' => true, // mandatory
'showMeridian' => false // irrelevant
),
)
);
?>
<?php
$this->widget('bootstrap.widgets.TbTimePicker',
array(
'name' => 'some_time',
'value' => '00:00',
'noAppend' => true, // mandatory
'options' => array(
'disableFocus' => true, // mandatory
'showMeridian' => false // irrelevant
)
)
);
?>
</div>
</div>
</div>
When I add new, Timepicker always on field 1. Can't on field changed.

(Zend) wrapping form element with multiple HtmlTags

I want to do this:
<div id="element-wrapper-1">
<span class="element-wrapper-2">
<input name="element" />
</span>
</div>
Is it possible to do this using only addDecorator methods? I do not want to write my own decorator class or render method.
You do like this:
$element->setDecorators(array(
'Viewhelper',
array(
array('span' => 'HtmlTag'),
array('tag' => 'span', 'class' => 'element-wrapper-2')
),
array(
array('div' => 'HtmlTag'),
array('tag' => 'div', 'class' => 'element-wrapper-1'))
)
);

Zend Form - how do I create these custom form elements?

This is a very specific instance where I'm having difficulty getting Zend Form to produce the correct output and supply the correct validation. I may have to go create a composite element but thought I'd ask here first. Here is the HTML I'm trying to get Zend Form to produce. I'd like this to be able to work where if the validation doesn't pass that the error messages still show up inline with the field that produced the error.
<tr>
<td>Budget</td>
<td>
<input type="radio" name="budget" value="unlimited" /> unlimited
<br />
<input type="radio" name="budget" value="limited" /> $ <input type="text" name="budget_amount" /> every <select name="budget_period">
<option value="day">day</option>
<option value="week">week</option>
<option value="month">month</option>
<option value="year">year</option>
</select>
</td>
</tr>
<tr>
<td></td>
<td><input type="checkbox" name="include_weekends" value="yes" /> include weekends?</td>
</tr>
The user can choose either unlimited or limited for the budget value, however, if they choose limited, then they are required to enter a value for the budget amount field and choose a value from the select for the budget period field.
Figured it out after lots of tweaking, but hopefully the answer will help someone else out. Just going to post the decorator stuff since I'm still working on the validation for the budget value (got it to work by overriding form's isValid() function but now trying to get it into a custom validator).
$this->setElementDecorators(array(
'ViewHelper',
array(array('data' => 'HtmlTag'), array('tag' => 'td')),
array('Label', array('tag' => 'td')),
array(array('row' => 'HtmlTag'), array('tag' => 'tr'))
));
$budget->setDecorators(array(
'ViewHelper',
array(array('openData' => 'HtmlTag'), array('tag' => 'td', 'openOnly' => true)),
array('Label', array('tag' => 'td')),
array(array('openRow' => 'HtmlTag'), array('tag' => 'tr', 'openOnly' => true))
));
$budgetAmount->setDecorators(array(
'ViewHelper'
));
$budgetPeriod->setDecorators(array(
'ViewHelper',
array('AnyMarkup', array('markup' => 'every', 'placement' => 'PREPEND')),
array(array('closeData' => 'HtmlTag'), array('tag' => 'td', 'closeOnly' => true)),
array(array('closeRow' => 'HtmlTag'), array('tag' => 'tr', 'closeOnly' => true))
));
$includeWeekends->setDecorators(array(
'ViewHelper',
array('Label', array('placement' => 'APPEND')),
array(array('data' => 'HtmlTag'), array('tag' => 'td')),
array(array('emptyRow' => 'HtmlTag'), array('tag' => 'td', 'placement' => 'PREPEND')),
array(array('row' => 'HtmlTag'), array('tag' => 'tr'))
));
$this->setDecorators(array(
'FormElements',
array('HtmlTag', array('tag' => 'table')),
'Form',
array('FormErrors', array('placement' => 'PREPEND', 'class' => 'error')),
array('Description', array('placement' => 'PREPEND'))
));