Decorating radio buttons in Zend Form - zend-form

I have a list of radio buttons, which came from the DB. I want to put each of them into a seperate "td". What I did is:
foreach ($notificationTypes as $key => $value) {
$radios->removeDecorator('DtDdWrapper');
$radios->removeDecorator('HtmlTag');
$radios->addMultiOption($value, $value . "_" . $i);
}
$radios->setDecorators($this->elementDecorators);
$this->addElement($radios);
And this is my decorator:
abstract class Myprj_Form_Abstract extends Zend_Form {
protected $elementDecorators = array(
'ViewHelper',
'Errors',
array(array('data' => 'HtmlTag'), array('tag' => 'td', 'class' => 'right_columns')),
array('Label', array('tag' => 'td')),
array(array('row' => 'HtmlTag'), array('tag' => 'tr')),
);
}
BUT, what I got is, all the radio buttons located into one td. I know I can do it into the View, but I want to do them into the Form. Is anyone know how to do that?
Thanks so much

I've found the answer, so I'm gonna share it....
I just needed to add
$radios->setSeperator('</td></tr><tr><td>');
Easy, na?
cheers,

Related

how to pass the id of the click CButtonColumn of CGridView going to the controller in Yii1.x?

I have a custom CButtonColumn within the CGridView.
one of the custom buttons is firing a CJuiDialog. now the problem is,
how to pass the id when clicked, so that the Controller will get the id, then I can do pass a model and renderPartial it inside the CJuiDialog?
here's what i have so far
'see' => array(
'label' => 'View',
'url' => 'Yii::app()->controller->createUrl("mycontrollerName/view,array("id" => "$data->id"))',
'click' => "function( e ){
e.preventDefault();
$( '#view-dialog' ).data('id',$(this).attr('id'))
.dialog( { title: 'View Details' } )
.dialog( 'open' ); }"
),
having given that code snippet.. in the controller action, I want to have the id ..is it $_GET['id'] ?, or $_POST['id'] ?..it doesn't matter for as long as I can get it so that I can use it to query in the model function
There are a few syntax errors in your code, but more importantly, you shouldn't wrap $data->id in any quotes.
'see' => array(
'label' => 'View',
'url' => 'Yii::app()->createUrl("mycontrollerName/view", array("id" => $data->id))',
'click' => "function( e ){
e.preventDefault();
$( '#view-dialog' ).data('id',$(this).attr('id'))
.dialog( { title: 'View Details' } )
.dialog( 'open' ); }",
),
So you are trying to pass the id value in the javascript code.
This is more of a jQuery issue rather than having much to do with Yii.
Run console.log($(this).attr('id')); you will probably see that you get an 'undefined' value. That is because the tag generated by Yii for the button does not contain an id parameter.
The easiest solution is to use jQuery to work with the url parameter.
e.g.
$( '#view-dialog' ).data('id',$(this).attr('href'))
if the entire URL is not needed, you could use a regex to parse only the numerical ID.
Alternatively you will have to pass the id in the buttons option parameter.
e.g.
'see' => array(
'label' => 'View',
'url' => 'Yii::app()->createUrl("mycontrollerName/view", array("id" => $data->id))',
'options' => array('id' => $data->id),
'click' => "function( e ){
...
However, please note that Yii will not render the value of $data->id in the 'option' parameter as this is not evaluated in CButtonColumn.
You will have to override Yii's CButtonColumn (see http://www.yiiframework.com/wiki/372/cbuttoncolumn-use-special-variable-data-for-the-id-in-the-options-of-a-button/)
Personally, if I were you, I'd implement some Javascript in some external code and have a regex to parse the id from the URL.

Yii widgets.TbThumbnails Pagination

I am using this 'widgets.TbThumbnails' from bootstrap to show the list of items as thumbnails. It shows first 10 items in one page and another 10 items on the other page. further it shows page navigator button at the bottom of the page. I tried to show all the items in a single page, but couldn't. If anyone know please help me to fix this. here is my code for thumbnail view
<?php $dataProvider = new CActiveDataProvider('Symptoms');
$this->widget('ext.bootstrap.widgets.TbThumbnails',
array(
'dataProvider' => $dataProvider,
//'template' => "{items}\n{pager}",
'itemView' => '_thumb',
//'htmlOptions' => array('style' => 'width:975px;','height:1020px'),
)
);
?>
Well that is due to the fact that dataProvider uses default settings for pagination.
Cpagination has a property named pageSize which refers to the the number of items per page. By default this is set to 10 thats why you can see 10 items per page.
Here is Official documentation.
You can do like this:
<?php
$dataProvider = new CActiveDataProvider('Symptoms', array(
'pagination'=>false
));
$this->widget('ext.bootstrap.widgets.TbThumbnails', array(
'dataProvider' => $dataProvider,
'itemView' => '_thumb',
)
);
?>

How to display values in a Kendo UI Grid custom popup template

I have a MVC View with a simple Kendo UI Grid:
#(Html.Kendo().Grid(Model.Positions)
.Name("Test")
.Columns(columns =>
{
columns.Bound(p => p.Name);
columns.Command(command => { command.Edit(); });
})
.Editable(ed=>ed.Mode(GridEditMode.PopUp).TemplateName("Position").Window(w => w.Width(600)).Window(w => w.Title("ByrÄ")))
.DataSource(dataSource => dataSource
.Ajax()
.PageSize(10)
.Model(model => model.Id(p => p.Id))
.Update(update => update.Action("Update", "Office"))
.Read(read => read.Action("Get", "Office")
)
)
)
Under Shared/EditorTemplate I have added Postion.cshtml under Shared/EditorTemplates. The edit open as it shoulds and everything is fine if I use for example:
#Html.TextBoxFor(model => model.Name)
However, I can't use LabelFor since that will display the name of the property and not the value. It also seems like the grid instantiate the popup together with the grid. The values in TextBoxFor is updated when I click on Edit, but if I use #Model.Name it does not. It will always be empty.
I also tried and hide some fields depending on the value of one of the fields, but since I can't use #Model it wont work.
Anyone know how to get around this?
One of Kendo's answers to me was something like this. I haven't got it to work in my case yet, but it might help you. If you came up with a different solution to this issue could you share it?
In you custom editor.
text/javascript
function sendName() {
var grid = $('.k-grid').data().kendoGrid;
var tr = grid.tbody.find('.k-grid-edit-row');
var model = grid.dataItem(tr);
var result = {
name: model.Name
};
return result;
}
They are inspecting the html and assigning first the grid, then the selected row of the grid then mapping the fields of the row to the columns of the Grid.

Yii multiple update of child records based on current parent record

I am trying to come up with a way of updating multiple records of a model and as I am using YiiBooster I have seen that you can do bulk actions using the Extended Grid.
Most of the examples that I have found on the web are showing how to delete multiple records using Ajax but my requirements are slightly different. As a newbie to Yii I am struggling to work out a suitable solution to this.
Basically I have 2 models, a parent and a child with a one-to-many relation. In the child model I have a field which references which parent it belongs to using the parent ID.
In the front end of the application the user is supposed to navigate to the parent update view and then see a list of all children assigned to that parent. I have created a modal window that shows a grid list of all children with the ability to perform a bulk update action. This will then assign the parent ID to all of the children that were selected.
Can anyone help me out with this as I am unsure what I need to edit in the extended grid view and controller that will be used to update the records?
In my parent update view I pull in the index view of the children using renderPartial, as follows:
<?php $this->renderPartial('application.modules.children.views.childviews.addChild', array('dataProvider' => new CActiveDataProvider('Children'))); ?>
I then have an Extended grid in my child index view:
<?php
$this->widget('bootstrap.widgets.TbExtendedGridView', array(
'type' => 'striped bordered',
'id' => 'children-grid',
'dataProvider' => $dataProvider,
'bulkActions' => array(
'actionButtons' => array(
array(
'buttonType' => 'link',
'type' => 'primary',
'size' => 'small',
'label' => 'Bulk Action',
'url' => array('batchUpdate'),
'htmlOptions' => array(
'class' => 'bulk-action'
),
'id' => 'child_id',
'click' => ''
)
),
'checkBoxColumnConfig' => array(
'name' => 'child_id'
),
),
'columns' => array(
'child_id',
'child_status',
'parent_id',
array(
'class' => 'bootstrap.widgets.TbButtonColumn',
'buttons' => array(
'update' => array(
'label' => '<i class="icon-user"></i> <span>View Child</span>',
'options' => array('class' => 'btn btn-small'),
'url' => 'Yii::app()->createUrl("children/update", array("id"=>$data->child_id))',
),
),
),
),
));
?>
I am guessing that I need some kind of onclick event that calls an update action in the controller and this action updates the parent_id column of all selected records to the parent id of the current parent update page?
I hope someone can help and many thanks in advance.
Instead of a one to many relationship as you stated in your question, it seams that you really want a many to many relationship. The reason I say that is you seem to want to select from a set of pre-defined properties for your auction. In that case you would display the parent (auction), and the list of perspective children (properties), and using a checkbox or something like that to indicate the selection of the perspective children. You will have to use a separate data model to record the selections. I don't have an example right now, but I will need to do something like this in my current Yii project, and I will blog about it when I get there.

Always show Pager on CGridView?

I've build a CGridView menu, and I want to always display the pager
(even when it's showing all the data and the navigation is not needed)
This is the current code I have:
$this->widget('zii.widgets.grid.CGridView',
array('dataProvider'=>$search,
'columns' => $columns,
'itemsCssClass' => 'list_table',
'template' => '{pager}{summary}{items}',
'pager' => array(
'cssFile'=>false,
'class'=>'CLinkPager',
'firstPageLabel' => '<<',
'prevPageLabel' => '<',
'nextPageLabel' => '>',
'lastPageLabel' => '>>',
'header' => '',
'footer' => $footer_btns,
),
'pagerCssClass' => 'pagination',
));
You could do this by overriding the renderPager() method -- however, it seems that the pager gets put together in a few files so one way to do it by only overriding one class would be to:
override zii.widgets.grid.CGridView to add your custom renderPager() method with something like:
Yii::import('zii.widgets.grid.CGridView');
class MyGrid extends CGridView {
public function renderPager() { ... }
}
the default renderPager() function is here.
What you want to do is look for the line that tests for pager content:
if($pager['pages']->getPageCount()>1) {
and change the "else" statement to put in your default "empty" pager content, which could use the same <ul> structure. Since you are not providing any navigation for the blank view, you don't need to worry about that data if this is used in multiple places. That could look something like:
else {
echo '<div class="'.$this->pagerCssClass.'">';
## YOUR CUSTOM "EMPTY PAGER" HTML HERE ##
echo '</div>';
}
You might need to define a couple extra css classes as well. On pages where only part of the pagination is showing (e.g., the first and last page), you can use CSS to redefine the ".hidden" class(es).