2

I am working with a custom plugin in Magento 2 that adds two radio fields after all the other inputs. Here is a photo of what it looks like:

enter image description here

When you click on the question mark, a tooltip shows up with some text. I want that text to be displayed right next to "Is Tax Exempt" after the radio buttons instead of being a tooltip, so that the message is always displayed. Here is the current code:

<?php

namespace Module\Checkout\Plugin\Block;

class LayoutProcessorPlugin
{
    public function afterProcess(\Magento\Checkout\Block\Checkout\LayoutProcessor $context, $result)
    {
        $newFields = [
            'is_residential' => 'Is Residential',
            'is_tax_exempt'  => 'Is Tax Exempt',
        ];

        $i = 1;
        foreach ($newFields as $newField => $newFieldLabel) {
            $customField = [
                'component' => 'Magento_Ui/js/form/element/checkbox-set',
                'config' => [
                    // customScope is used to group elements within a single form (e.g. they can be validated separately)
                    'customScope' => 'shippingAddress.custom_attributes',
                    'customEntry' => null,
                    'multiple' => false,
                    'template' => 'ui/form/field',
                    'elementTmpl' => 'ui/form/element/checkbox-set',
                ],
                'additionalClasses' => 'custom-field-radio',
                'dataScope' => 'shippingAddress.custom_attributes.' . $newField,
                'label' => $newFieldLabel,
                'provider' => 'checkoutProvider',
                'sortOrder' => 200 + $i,
                'validation' => [
                    'required-entry' => true
                ],
                'filterBy' => null,
                'customEntry' => null,
                'visible' => true,
                'options' => [
                    ['value' => '1', 'label' => 'Yes'],
                    ['value' => '0', 'label' => 'No'],
                ],
                'valueMap' => [
                    '1' => true,
                    '0' => false
                ]
            ];

            if ($newField == 'is_tax_exempt') {
                $customField['tooltip']['description'] = 'Text I want to display next to radio buttons';
            }

            $result['components']['checkout']['children']['steps']['children']['shipping-step']['children']['shippingAddress']['children']['shipping-address-fieldset']['children'][$newField] = $customField;

            $i++;
        }

        return $result;
    }
}
0

Try following way:


$customField['config']['tooltip']['description'] = 'Text I want to display next to radio buttons';
  • Did nothing, the tooltip is still there. – Eric Brown Feb 13 at 17:54
0

Add below line after dataScope

'description' => __('custom text'),

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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