How to get a Field of type “image” not to have a delete checkbox?
Question
How to get a Field of type "image" not to have a delete checkbox ? As it's a required attribute for my form, I don't need the delete checkbox.
Here is my addField example :
$fieldset->addField('filename', 'image', array(
'label' => Mage::helper('example')->__('Example image'),
'required' => true,
'name' => 'filename',
));
Solution
You need to create a custom renderer for the image.
For this create a class in one of your modules called [Namespace]_[Module]_Block_Adminhtml_Helper_Image_Required
with this content
<?php
class [Namespace]_[Module]_Block_Adminhtml_Helper_Image_Required extends Varien_Data_Form_Element_Image{
protected function _getDeleteCheckbox()
{
return '';
}
}
Then in your form block, right above your field (or higher) add this lines
$fieldset->addType('required_image', '[Namespace]_[Module]_Block_Adminhtml_Helper_Image_Required');
and define your field like this:
$fieldset->addField('filename', 'required_image', array(
'label' => Mage::helper('example')->__('Example image'),
'required' => true,
'name' => 'filename',
));
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange