25

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/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <type name="Magento\User\Block\User\Edit\...


19

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"> <item name="label" xsi:type="string">Status</item> <item name="dataType" xsi:type="string">number</item> &...


16

Discovered I was missing the Config setting: /** * @var \Magento\Cms\Model\Wysiwyg\Config */ protected $_wysiwygConfig; /** * @param \Magento\Backend\Block\Template\Context $context * @param \Magento\Framework\Registry $registry * @param \Magento\Framework\Data\FormFactory $formFactory * @param \Magento\Cms\Model\Wysiwyg\Config $wysiwygConfig * @...


15

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 solution. inject this \Magento\Framework\Filesystem\Driver\File $file in your constructor (make sure to declare class level variable i.e, protected $_file;) ...


13

Renderer file: class [NameSpace]_[ModuleName]_Block_Adminhtml_Review_Renderer_Images extends Varien_Data_Form_Element_Abstract { protected $_element; public function getElementHtml() { $html = ''; $html = $html.'<input id="input-21d" name="rating" value='2' type="number" class="rating" min=0 max=5 step=0.5 data-size=...


13

Add this in the method you mentioned $this->_removeButton('save'); $this->_removeButton('delete'); $this->_removeButton('reset');


13

I was able to get solution using the below code: $objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $groupOptions = $objectManager->get('\Magento\Customer\Model\ResourceModel\Group\Collection')->toOptionArray(); $fieldset->addField( 'customer_group', 'multiselect', [ 'name' => 'customer_group[]', '...


13

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/code/Vendor/Rules/Setup/InstallSchema.php <?php namespace Vendor\Rules\Setup; use Magento\Framework\DB\Ddl\Table; use Magento\Framework\Setup\...


12

I would advise never editing core code as it will create issues for you down the road. This is a database change. 0 comes before 1 and no default value is set for that attribute so 0 will always be selected unless otherwise told. You need to go into your database, find the "is_active" attribute code (there may be two, only edit the one with the Source ...


12

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' => ['id' => 'edit_form', 'enctype'=>'multipart/form-data','action' => $this->getData('action'), 'method' => 'post']] );


11

When you have a model which is an type of Mage_Core_Model_Abstract, then you can easily get the previous data (original data) on save using public function getOrigData($key=null) method. But there are two other methods that might be helpful in your case. There is a method to know if the values has changed or not public function hasDataChanges(). So using ...


9

Add the code in your controller file public function saveAction() { ... if (!empty( $_FILES['main_image']['name'] )) { $data['main_image'] = $_FILES['main_image']['name'] ; } else { if (isset($data['main_image']['delete']) && $data['main_image']['delete'] == 1) { if ($data['main_image']['...


9

Add the following code in your execute function of Save Controller (Module/Controller/Adminhtml/Example/Save.php) public function execute() { $resultRedirect = $this->resultRedirectFactory->create(); $data = $this->getRequest()->getPostValue(); if ($data) { try{ $id = $data['id']; ...


9

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\Listing\Column\Cms\Options</item> <item name="config" xsi:type="array"> <item name="dataType" xsi:type="string">int</item> ...


8

Try using Magento's validator's validate-date-range class on your fields. If you add this to both fields then it will get the to date and compare the two values. If get the to date value using the following code: var m = /\bdate-range-(\w+)-(\w+)\b/.exec(elm.className); if (!m || m[2] == 'to' || Validation.get('IsEmpty').test(v)) { return true; } So ...


8

Found the problem, was missing a step in my controller. $postData = $this->getRequest()->getPost(); $postData = $this->_filterDates($postData, array("date")); After using _filterDates it started saving correctly


8

You form must have form key to allow submit data. See formkey.phtml that used in core forms


8

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( 'color', 'text', [ 'name' => 'color', 'label' => __('Color'), 'title' => __('Color') ] ); $...


8

Try this $fieldset->addField( 'customer_id', 'text', [ 'label' => __('Customer Id'), 'title' => __('Customer Id'), 'name' => 'customer_id', 'required' => true, ] ); $model->setData('customer_id', '10'); Second way: You can achieve this using following way also. $fieldset->...


8

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();


8

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 of code is working fine. i think this error is occurred because we can not use tab structure and collapsible structure in single UI component form.


7

It should work with value: $fieldset->addField('register', 'button', array( 'value' => Mage::helper('module')->__('Button Caption'), 'onclick' => 'test()' )); Just make sure that at the end of your form declaration you don't do this: $form->setValues(....) This will override the value of the button input. Use this instead. $...


7

It's easier than that. I have described it in full at http://www.integer-net.com/2015/03/17/how-to-create-tables-in-magento-system-configuration/. In short: system.xml: <shipping_costs translate="label"> <label>Shipping Cost based on Price</label> <frontend_model>namespace_module/config_shippingCosts</frontend_model> ...


7

I got it now, instead of using $form->setValues(), I used $form->addValues() as the former overrides the value of the fields.


7

Can you try to add following under global tag in config.xml: <blocks> <Mymodule> <class>Mynamespace_Mymodule_Block</class> </Mymodule> </blocks>


7

On your latest screenshot I see that the fields you are submitting don't have a name. Look at the input with the id product_id for example. the name attribute is empty. I think the problem comes from the way you defined your fields. Let's take this for example: $fieldset->addField('product_id', 'text', array( 'label' => 'Product ID'...


7

Try this <?php $installer = $this; $attribute = array( 'type' => 'int', 'input' => 'text', 'label' => 'Is Active', 'global' => 1, 'visible' => 1, 'default' => '0', 'required' => 0, 'user_defined' => 0, 'used_in_forms' => array( 'adminhtml_customer', ), 'comment' => 'Flag ...


7

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


7

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 must be name of your uiform like <uiComponent name="product_form"/>. e.g. <input type="text" data-form-part="product_form" name="test" value="Hello ...


7

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 newAction action in our controller like this: Pfay/Contacts/Controller/Adminhtml/Contact/NewAction.php <?php namespace Pfay\Contacts\Controller\Adminhtml\Test; ...


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