1

I've created a module that adds a custom form inside magento which is similar to the create order or create product forms. The form is used to create requests for marketing material from our art department.

I have successfully created my form partly thanks to this tutorial but one piece is missing. What I'm trying to do is add a field with two side-by-side items (a select box and a text input).

Magento has the exact functionality I need built in, two examples include Magento\CatalogInventory\Block\Adminhtml\Form\Field\Minsaleqty: Minsaleqty form field Magento\Config\Block\System\Config\Form\Field\Regexceptions: Regexceptions form field

However, I can't figure out how to alter these for use in an admin form. In case my terminology is unclear, the above fields are added using system.xml like so:

#file module-catalog-inventory/etc/adminhtml/system.xml
<field id="min_sale_qty" translate="label" sortOrder="6" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
    <label>Minimum Qty Allowed in Shopping Cart</label>
    <frontend_model>Magento\CatalogInventory\Block\Adminhtml\Form\Field\Minsaleqty</frontend_model>
    <backend_model>Magento\CatalogInventory\Model\System\Config\Backend\Minsaleqty</backend_model>
</field>

Whereas my fields are built by extending Magento\Backend\Block\Widget\Grid\Container and creating tabs that add fields using php methods. Here is one tab:

namespace Vendor\Module\Block\Adminhtml\SaleSheets\Edit\Tab;
class Info extends Generic implements TabInterface
{
    protected function _prepareForm()
    {   
        /** @var $model \Vendor\Module\Model\SaleSheets */
        $model = $this->_coreRegistry->registry('vendor_salesheets');
        /** @var \Magento\Framework\Data\Form $form */
        $form = $this->_formFactory->create();
        $form->setHtmlIdPrefix('salesheets_');
        $form->setFieldNameSuffix('salesheets');

        $fieldset = $form->addFieldset(
            'base_fieldset',
            ['legend' => __('General')]
        );

        if ($model->getId()) {
            $fieldset->addField(
                'id',
                'hidden',
                ['name' => 'id']
            );
        }

        // ...additional fields for this tab

        $data = $model->getData();
        $form->setValues($data);
        $this->setForm($form);
        return parent::_prepareForm();
    }

}

Result:enter image description here

My end result will be an additional field to my form that is repeatable with the Add and Delete action, and which includes a select box and an empty text field for additional details. How can I get this functionality in my admin form? Any help for this would be appreciated, including tutorials or even pointing me to a plugin that does something similar that I can buy just to reference.

3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.