Skip to main content
Share Your Experience: Take the 2024 Developer Survey
33 votes
Accepted

Magento 2 Add new field to Magento_User admin form

For adding image field, you can try using plugin and always try to avoid overwrite whole class. Vendor/Module/etc/adminhtml/di.xml <?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/...
Sohel Rana's user avatar
  • 35.9k
28 votes
Accepted

How to make a form field readonly using ui-components?

Try to add the disabled parameter to the element like this: <field name="is_active"> <argument name="data" xsi:type="array"> <item name="config" xsi:type="array"> ...
Siarhey Uchukhlebau's user avatar
17 votes
Accepted

Magento 2: how to delete image or file

Very important question as in my experience, when submitting an extension for marketplace, the validation generated errors regarding using of such method directly. I've researched and found following ...
R T's user avatar
  • 1,347
17 votes
Accepted

Add WYSIWYG Editor to Block Form in Magento 2

Discovered I was missing the Config setting: /** * @var \Magento\Cms\Model\Wysiwyg\Config */ protected $_wysiwygConfig; /** * @param \Magento\Backend\Block\Template\Context $context * @param \...
tim.baker's user avatar
  • 843
16 votes
Accepted

How to get all list of customer group?

I was able to get solution using the below code: $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $groupOptions = $objectManager->get('\Magento\Customer\Model\ResourceModel\...
Prashant Valanda's user avatar
14 votes

Magento Add Condition Rule In A Custom Form in magento 2

To add a conditional field to the default model (and further utilize it for validating purposes), you will need to create a new model (or modify the existing one) that contains these fields. app/...
Mageworx's user avatar
  • 3,566
14 votes
Accepted

Magento 2: How to submit custom html content from ui_form to controller?

In your block create protected $_template = 'Company_Module::labelposition.phtml'; now, make labelposition.phtml and add your html field with attribute data-form-part="formname". Here the formname ...
SyncTechnolab's user avatar
13 votes
Accepted

$_File array empty in Magento 2 while Uploading file at admin form

It was my bad !! I forgot to add enctype'=>'multipart/form-data You have to add following code while creating formFactory $form = $this->_formFactory->create( ['data' => ...
Bhupendra Jadeja's user avatar
13 votes
Accepted

Magento 2.2.6 How to add TAB structure in admin UI component form

I found my problem, i used argument item <item name="template" xsi:type="string">templates/form/collapsible</item> it is used to display for collapsible structure. After remove this line ...
Chirag Patel's user avatar
  • 6,136
12 votes
Accepted

Field comments in ui_component form

You should use notice: <item name="notice" xsi:type="string" translate="true"> Full example: <field name="name"> <argument name="data" xsi:type="array"> ...
Claudiu Creanga's user avatar
11 votes

Magento 2:Store View in Ui Component Form

Add following code into your ui_component form <field name="storeviews"> <argument name="data" xsi:type="array"> <item name="options" xsi:type="object">Magento\Cms\Ui\Component\...
Sohel Rana's user avatar
  • 35.9k
11 votes
Accepted

How to add a color picker field in Admin form?

Never mind guys, I resolved the problem. Step 1: app/code/Vendor/Module/Block/Adminhtml/Module/Edit/Tab/Main.php //Replace your db field name with "color" $field = $fieldset->addField( ...
Abhishek Panchal's user avatar
11 votes
Accepted

Magento 2 How to set value to UI component hidden field using Jquery or Javascript

You need to use change() function after val() called. When you used val() of jquery in knockout context at that time you need to use below syntax, $('input[name="image_data"]').val(Data).change();
Rakesh Jesadiya's user avatar
11 votes

Magento 2.3.0 While edit UI component form data not filled up in custom module

If you use setting tags in ui-component. You need to add data return include fieldset. Example field "priority" will show "name='general['priority']' " Your loadedData in function getData() should ...
the light's user avatar
  • 718
10 votes
Accepted

Magento 2 ui component form without database table

For this, Your Data Provider should be like <dataSource name="coupon_email_data_source"> <argument name="dataProvider" xsi:type="configurableObject"> <argument name=...
Smita Kagwade's user avatar
10 votes
Accepted

Magento2 admin grid ui component form hide multiple fields based on php condition

Override getMeta function in your dataprovider and set value like this. my form.xml <fieldset name="fieldset_name"> <field name="attribute_id"> ...
Dharmendra Jadav's user avatar
9 votes

How to get all list of customer group?

You can use the following class: Magento\Customer\Model\Customer\Source\Group. It provides a toOptionArray method that you can use to get an array of customer groups
Raphael at Digital Pianism's user avatar
9 votes
Accepted

Magento 2 : Could not save admin form contents into the DB

Add the following code in your execute function of Save Controller (Module/Controller/Adminhtml/Example/Save.php) public function execute() { $resultRedirect = $this->...
Jancy Abraham's user avatar
9 votes
Accepted

Input type number in admin edit form Magento 2

Try this code :- $fieldset->addField( 'sorting_order', 'text', array( 'name' => 'sorting_order', 'label' => __('Sort Order'...
Rohan Hapani's user avatar
  • 17.4k
8 votes
Accepted

Admin form redirect to dashboard - Magento2

You form must have form key to allow submit data. See formkey.phtml that used in core forms
KAndy's user avatar
  • 20.9k
8 votes
Accepted

Magento 2: How add dropdown in admin form?

Change Category class by following code: namespace Book\Flip\Model\Source; class Category implements \Magento\Framework\Option\ArrayInterface { /** * Retrieve options array. * * @...
Sohel Rana's user avatar
  • 35.9k
8 votes
Accepted

How to create and add Backend form to Custom admin grid in magento 2

If you just need to create an admin form, have a look at here. https://www.pierrefay.com/magento2-training/form-component-backend-crud-admin.html To create our Form, we will first create the ...
Dinesh Yadav's user avatar
  • 6,457
8 votes
Accepted

How to set default text field value in form Magento 2

Try this $fieldset->addField( 'customer_id', 'text', [ 'label' => __('Customer Id'), 'title' => __('Customer Id'), 'name' => 'customer_id', ...
Dinesh Yadav's user avatar
  • 6,457
8 votes
Accepted

Magento 2 - Unable to add record in dynamic rows in admin product edit page

I found the issue. The issue is from the linking property "links". The links property is missed while adding more than one record. So the datascope configuration is most important for the &...
Siranjeevi K S's user avatar
7 votes

Magento 2: how to delete image or file

The answer of RT is good, but we should not use the ObjectManager directly in the example. The reason is here "Magento 2: to use or not to use the ObjectManager directly". So better example is below:...
Key Shang's user avatar
  • 3,425
7 votes
Accepted

Magento 2 : Selected categories are not visible in edit form

In that case you need to modify getData function. For edit category_ids value must be an array.Suppose category_ids value save in db as comma separated that means '7,9,22'. So when you edit this ...
Sohel Rana's user avatar
  • 35.9k
7 votes
Accepted

Magento2 not getting post data from ui component phtml file

You have to just add data-form-part="forrname_form" in your input filed forrname_form it's must be similar with your ui form name your code shold be like now: <tr> &...
Rutvee Sojitra's user avatar
7 votes
Accepted

Submit custom form in Magento 2.3 admin

Your controller should extend Magento\Backend\App\Action and implements Magento\Framework\App\Action\HttpPostActionInterface, also don't forget about ACL. So should look something like this: ...
underser's user avatar
  • 550
6 votes
Accepted

Magento2 : How to add delete button in custom form in backend

Add below code in app\code\Vendor\ModuleName\Block\Adminhtml\Module\Edit.php in _construct() protected function _construct(){ $this->addButton( 'delete', [ ...
Ajay's user avatar
  • 919
6 votes
Accepted

How to add radio option in Magento 2?

change type from radio to radios $fieldset->addField( 'test', 'radios', [ 'label' => __('test'), 'title' => __('test'), ...
R T's user avatar
  • 1,347

Only top scored, non community-wiki answers of a minimum length are eligible