I have add an image upload field in my modules edit form using-
$fieldset->addField(
'image',
'image',
[
'name' => 'image',
'label' => __('Image'),
'id' => 'image',
'title' => __('Image'),
'class' => 'required-entry',
'required' => true,
]
);
While editing row it displays checkbox to delete image, I have only one image upload field and that is required also. So I want to remove this checkbox. How can I remove this checkbox?
-
2a similar solution exists in magento-1.x magento.stackexchange.com/a/73870 so you can use the same for magento 2Manashvi Birla– Manashvi Birla2017年06月08日 12:07:28 +00:00Commented Jun 8, 2017 at 12:07
1 Answer 1
As @Manashvi Suggested I tried to solve it the way it was done in Magento 1.x and it worked. I created a custom renderer for the image. and created a class in my module
[Namespace]_[Module]_Block_Adminhtml_Helper_Image_Required with this content
class Required extends \Magento\Framework\Data\Form\Element\Image
{
protected function _getDeleteCheckbox()
{
return '';
}
}
Then in my form block, right above field added this lines
$fieldset->addType('required_image', 'Namespace\Module\Block\Adminhtml\Helper\Image\Required');
and defined field like this:
$fieldset->addField(
'image',
'required_image', [
'name' => 'image',
'label' => __('Image'),
'id' => 'image',
'title' => __('Image'),
'class' => 'required-entry',
'required' => true,
]
);
-
I am trying to achieve the same. but i get error: Cannot declare class Required because the name is already in use. Even i change it's name to something else, still i get same error with that name. Any idea?Khushbu– Khushbu2019年02月28日 09:58:23 +00:00Commented Feb 28, 2019 at 9:58
-
such issue occurs in case when you have declared same class more than once, please check your file path and class namePiyush– Piyush2019年02月28日 09:59:50 +00:00Commented Feb 28, 2019 at 9:59
-
but even if i change class name to any other name for e.g. RequiredImage, Still i get the same error: Cannot declare class RequiredImage because the name is already in use. (i am using magento 2.2)Khushbu– Khushbu2019年02月28日 10:03:07 +00:00Commented Feb 28, 2019 at 10:03
-
Ok i found the issue. Just forgot to add namespace line on top of the class file!Khushbu– Khushbu2019年02月28日 10:09:22 +00:00Commented Feb 28, 2019 at 10:09
Explore related questions
See similar questions with these tags.