In my customization I need a multiselect field in form so I added new field and created a renderer hoping it will work and I've done it this way:
... form.php
$fieldset->addField('test', 'multiselect', array(
'name' => 'test',
'label' => Mage::helper('cms')->__('Test'),
'title' => Mage::helper('cms')->__('Test'),
//'onchange' => "alert('onchange')",
'class' => 'sortable',
'values' => new Mage_Adminhtml_Block_Cms_Block_Renderer_Test(),
));
and so far .... it works, then my renderer
class Mage_Adminhtml_Block_Cms_Block_Renderer_Test
extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract {
public function render() {
// getting banners data filtering by "is_slider = true"
$myBanners = Mage::getModel( 'cms/block' )->getCollection()
->addFieldToSelect('identifier')
->addFieldToFilter( 'is_slider', true )
;
foreach($myBanners as $banner){
$output[] = array(
'value' => $banner->getData('entity_id'),
'label' => $banner->getData('identifier'),
);
}
return $output;
}
}
Is my approach correct ? Of course it does not work yet, at least I can't see any positive results except a multiselect grid/table with around 7 selected "empty lines" How should I do it ?
In effect of this I'm getting:
<tr>
<td class="label"><label for="block_bannerIds">Test</label></td>
<td class="value">
<select id="block_bannerIds" name="test[]" title="Test" class="sortable select multiselect" size="10" multiple="multiple">
<option value="" selected="selected"></option>
<option value="" selected="selected"></option>
<option value="" selected="selected"></option>
<option value="" selected="selected"></option>
<option value="" selected="selected"></option>
<option value="" selected="selected"></option>
<option value="" selected="selected"></option>
</select>
</td>
</tr>
addOptionArray()
rather thanrender()
?