28

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\...


23

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

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


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 * @...


14

Renderer file: class NameSpace]_[ModuleName]_Block_Adminhtml_Review_Renderer_Images extends Varien_Data_Form_Element_Abstract { public function getElementHtml() { $html = ''; $html = $html.'<input id="input-21d" name="rating" value="2" type="number" class="...


14

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\...


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

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']] );


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 ...


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 ...


10

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> ...


9

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') ] ); $...


9

Try this code :- $fieldset->addField( 'sorting_order', 'text', array( 'name' => 'sorting_order', 'label' => __('Sort Order'), 'title' => __('Sort Order'), 'required' => false, 'class' => 'validate-number' ) );


9

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 ...


9

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


9

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.


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

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'...


8

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


8

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


8

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; ...


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

Override getMeta function in your dataprovider and set value like this. my form.xml <fieldset name="fieldset_name"> <field name="attribute_id"> <argument name="data" xsi:type="array"> <item name="options" xsi:type="object">Vendor\Module\Model\Source\Attributes</item&...


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

Add 'enctype'’ ⇒ 'multipart/form-data' That should help to get something in $_FILES in /app/code/local/Chilly/ModName/Block/Adminhtml/ModName/Edit/Form.php You should have something looking like this: $form = new Varien_Data_Form(array( 'id' => 'edit_form', 'action' => $this->getUrl('*/*/save', array('id' => $this->...


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> ...


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