0

I want to add a Multiline Input "Textarea" in system.xml searched but not found if anyone can help me

thank you

EDIT

This is how I have created Dynamic Rows

use Vendor\Module\Block\System\Config\Form\Field\FieldArray\AbstractFieldArray;
use Magento\Framework\DataObject;

class SMSTemplates extends AbstractFieldArray
{
    /**
     * @var SortOrder
     */
    private $orderStatusRenderer;
    
    /**
     * @var Status
     */
    private $statusRenderer;
    
    /**
     * @var Icons
     */
    private $templateRenderer;

    /**
     * Render Sort Order
     *
     * @return SortOrder
     */
    protected function getOrderStatusRenderer()
    {
        if (!$this->orderStatusRenderer) {
            $this->orderStatusRenderer = $this->getLayout()->createBlock(
                OrderStatus::class,
                '',
                ['data' => ['is_render_to_js_template' => true]]
            );
        }
        return $this->orderStatusRenderer;
    }
    /**
     * Render Status
     *
     * @return Status
     */
    protected function getStatusRenderer()
    {
        if (!$this->statusRenderer) {
            $this->statusRenderer = $this->getLayout()->createBlock(
                Status::class,
                '',
                ['data' => ['is_render_to_js_template' => true]]
            );
        }
        return $this->statusRenderer;
    }
    /**
     * Render Icons 
     *
     * @return Icons
     */
    protected function getTemplateRenderer()
    {
        if (!$this->templateRenderer) {
            $this->templateRenderer = $this->getLayout()->createBlock(
                Tempalate::class,
                '',
                ['data' => ['is_render_to_js_template' => true]]
            );
        }
        return $this->templateRenderer;
    }

    /**
     * Prepare rendering the new field by adding all the needed columns
     */
    protected function _prepareToRender()
    {
        $this->addColumn('order_status', 
            [
                'label' => __('Order Status'), 
                'class' => 'required-entry',
            ]
        );
        $this->addColumn('status', 
            [
                'label' => __('Status'), 
                'renderer'  => $this->getStatusRenderer(),
            ]
        );
        $this->addColumn('template', 
            [
                'label' => __('Template'), 
                'class' => 'textarea',
                'style' => 'textarea'

            ]
        );
        $this->_addAfter = false;
        $this->_addButtonLabel = __('Add');
    }
    /**
     * Prepare existing row data object
     *
     * @param DataObject $row
     * @return void
     */
    protected function _prepareArrayRow(DataObject $row)
    {
        $orderStatus = $row->getOrderStatus();
        $options = []; 
        if($orderStatus != Null ){
            $status = $row->getStatus();    
            $options['option_' . $this->getStatusRenderer()->calcOptionHash($status)] = 'selected="selected"';
        }
        $orderStatus = $row->getStatus();
        if($_FILES != Null){    
            $options['option_' . $this->getOrderStatusRenderer()->calcOptionHash($orderStatus)] = 'selected="selected"';
        }
        $template = $row->getTemplate();
        if($template != Null){  
            $options['option_' . $this->getTemplateRenderer()->calcOptionHash($template)] = 'selected="selected"';
        }   
        $row->setData('option_extra_attrs', $options);
    }

    /**
     * Render Feilds Styling
     *
     * @param array $columnName
     *
     * @return void
     */
    public function renderCellTemplate($columnName)
    {
        if ($columnName == "order_status") {
            $this->_columns[$columnName]['class'] = 'input-text required-entry';
            $this->_columns[$columnName]['style'] = 'width:150px';
        }elseif ($columnName == "template") {
            $this->_columns[$columnName]['class'] = 'input-text required-entry';
            $this->_columns[$columnName]['style'] = 'width:200px; height:200px;';
        }
        return parent::renderCellTemplate($columnName);
    }
}

Here is My System.xml

<group id="sms_templates_settings" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0">
     <label>SMS Templates</label>
     <field id="sms_templates" translate="label" sortOrder="101" showInDefault="1" showInWebsite="1" showInStore="1">
     <label></label>
                <frontend_model>Vendor\Module\Block\Adminhtml\Form\Field\SMSTemplates</frontend_model>
                    <backend_model>Vendor\Module\Model\Adminhtml\System\Config\SMSTemplates</backend_model>
                </field>
            </group>

this is how its Gernating but I need last field to me multline

enter image description here

4
  • Please share your code how you're generating dynamic rows – Natha Odedara Aug 30 '20 at 4:15
  • please see question now – Real Magento Man Aug 30 '20 at 4:19
  • can you please share system.xml so I can generate same on my system – Natha Odedara Aug 30 '20 at 4:33
  • i have edited again please see – Real Magento Man Aug 30 '20 at 4:36
1

You can get an idea from this one https://gist.github.com/ianitsky/852d4d51bd559612235e8c0c7fbc8e76

You have to do the same as you have done for dropdown

OK Please check this

Please change namespace and class of your choice I am putting example

In your case please add this in SMSTemplates

/**
     * @return \Magento\Framework\View\Element\BlockInterface
     * @throws \Magento\Framework\Exception\LocalizedException
     */
    private function textAreaTypes()
    {
        if (!$this->textAreaType) {
            $this->textAreaType = $this->getLayout()->createBlock(
                '\Nilesh\Prefech\Block\Adminhtml\Form\Field\Textarea',
                ''
            );
        }

        return $this->textAreaType;
    }

$this->addColumn(
            'sort_order',
            [
                'label' => __('Sort Order'),
                'renderer' => $this->textAreaTypes()
            ]
        );

Render file

<?php    
namespace Nilesh\Prefech\Block\Adminhtml\Form\Field;
    
    // use Magento\Framework\View\Element\Context;
    
    class Textarea extends \Magento\Framework\View\Element\Template
    {
        /**
         * @return string
         */
        public function _toHtml()
        {
            $inputName = $this->getInputName();
            $columnName = $this->getColumnName();
            $column = $this->getColumn();
    
            return '<textarea id="' . $this->getInputId().'" name="' . $inputName . '" ' .
                ($column['size'] ? 'size="' . $column['size'] . '"' : '') . ' class="' .
                (isset($column['class']) ? $column['class'] : 'input-text') . '"'.
                (isset($column['style']) ? ' style="'.$column['style'] . '"' : '') . '></textarea>';
        }
    }

Thanks

3
  • i have no idea of Magento 1 can you please convert that code for me in Magento 2 ? thank you – Real Magento Man Aug 30 '20 at 9:15
  • Please see it might help you – Nilesh Dubey Sep 3 '20 at 16:19
  • thank you so much its working perfectly fine – Real Magento Man Sep 11 '20 at 17:55

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.