0

I need help, I would like to set a maximum size for the message text area in gift options in magento 2.

enter image description here

I'm a beginner in magento development, and any help will be happy.

1 Answer 1

0

Create this below page in your custom module

app/code/Vendor/Module/etc/adminhtml/system.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Config:etc/system_file.xsd">
    <system>
        <tab id="custom_tab" translate="label" sortOrder="10">
            <label>Custom Tab</label>
        </tab>
        <section id="custom" translate="label" sortOrder="130" showInDefault="1" showInWebsite="1" showInStore="1">
            <label>Custom Settings</label>
            <tab>custom_tab</tab>
            <resource>Vendor_Module::module_config</resource>
            <group id="gift" translate="label" type="text" sortOrder="10" showInDefault="1" showInWebsite="0" showInStore="0">
                <label>Gift Message Configuration</label>
                <field id="message_size" translate="label" type="text" sortOrder="1" showInDefault="1" showInWebsite="0" showInStore="0">
                    <label>Message Box Size</label>
                </field>
            </group>
        </section>
    </system>
</config>

Then you update in textarea page:

<?php 
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$scopeConfig= $objectManager->create('\Magento\Framework\App\Config\ScopeConfigInterface');
$storeScope = \Magento\Store\Model\ScopeInterface::SCOPE_STORE;
?>
<textarea maxlength="<?php echo $this->scopeConfig->getValue('custom/gift/message_size', $storeScope); ?>"></textarea>

Then run:

php bin/magento setup:upgrade

4
  • Thanks for the answer, I came to that conclusion. But I would like to make this dynamic and configurable in the admin panel.
    – Paul
    Aug 19, 2020 at 16:11
  • Could you tell me a way to do this?
    – Paul
    Aug 19, 2020 at 16:21
  • By this above process you can set max size from magento admin. Aug 19, 2020 at 16:46
  • 1
    Thank you! I regret the delay in responding. But only today did I reach the goal, following your code as an example.
    – Paul
    Aug 25, 2020 at 12:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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