0

want to show radio button and checkbox in customer registration page and admin panel... I need exactly radio button and checkbox... But most of the friends mentioned in his/her blog on 'input'=>'boollean', it's not fulfilling my requirement.... Can anyone help me to create the custom customer attribute as radio and checkbox?

4
  • If you are trying to add attribute via install/upgrade data script then you can add value for "input" to required type. It could be 'input' => 'image', 'input' => 'text','input' => 'radio', 'input' => 'checkbox' give a try and let me know if it helps.. Nov 23, 2018 at 6:54
  • 'input' => 'image', 'input' => 'text','input' => 'radio', 'input' => 'checkbox' it's not working
    – Ajithkumar
    Nov 23, 2018 at 10:23
  • I had a check and found that 'input'=>'boollean' is also creating a checkbox but some additional css added by magento team to get customized look. You can overwrite that css for your particular pages in case.. Nov 23, 2018 at 13:14
  • see the following i think this is exactly what you need magento.stackexchange.com/questions/263675/… Feb 28, 2019 at 7:28

1 Answer 1

0

Create Extension and your setup file below
here customer=>namespace & Attribute=>Extension name

namespace Customer\Attribute\Setup;

use Magento\Eav\Model\Config;
use Magento\Eav\Model\Entity\Setup\Context;
use Magento\Eav\Setup\EavSetup;
use Magento\Framework\App\CacheInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Eav\Model\ResourceModel\Entity\Attribute\Group\CollectionFactory;

class CustomerSetup extends EavSetup {

    protected $eavConfig;

    public function __construct(
        ModuleDataSetupInterface $setup,
        Context $context,
        CacheInterface $cache,
        CollectionFactory $attrGroupCollectionFactory,
        Config $eavConfig
        ) {
        $this -> eavConfig = $eavConfig;
        parent :: __construct($setup, $context, $cache, $attrGroupCollectionFactory);
    } 

    public function installAttributes($customerSetup) {
        $this -> installCustomerAttributes($customerSetup);
        $this -> installCustomerAddressAttributes($customerSetup);
    } 

    public function installCustomerAttributes($customerSetup) {


        $customerSetup -> addAttribute(\Magento\Customer\Model\Customer::ENTITY,
            'dropdown',
            [
            'label' => 'Radio Button',
            'system' => 0,
            'position' => 100,
            'sort_order' =>100,
            'visible' =>  true,
            'note' => '',


                        'type' => 'int',
                        'input' => 'select',
                        'source' => 'Magento\Eav\Model\Entity\Attribute\Source\Boolean',

            ]
            );

        $customerSetup -> getEavConfig() -> getAttribute('customer', 'dropdown')->setData('is_user_defined',1)->setData('is_required',0)->setData('default_value','')->setData('used_in_forms', ['adminhtml_customer', 'checkout_register', 'customer_account_create', 'customer_account_edit', 'adminhtml_checkout']) -> save();



        $customerSetup -> addAttribute(\Magento\Customer\Model\Customer::ENTITY,
            'multiple',
            [
            'label' => 'Multiple',
            'system' => 0,
            'position' => 100,
            'sort_order' =>100,
            'visible' =>  true,
            'note' => '',


                        'type' => 'varchar',
                        'input' => 'multiselect',
                        'source' => 'Magento\Eav\Model\Entity\Attribute\Source\Boolean',
                        'backend' => 'Magento\Eav\Model\Entity\Attribute\Backend\ArrayBackend',

            ]
            );

        $customerSetup -> getEavConfig() -> getAttribute('customer', 'multiple')->setData('is_user_defined',1)->setData('is_required',0)->setData('default_value','')->setData('used_in_forms', ['adminhtml_customer', 'checkout_register', 'customer_account_create', 'customer_account_edit', 'adminhtml_checkout']) -> save();


    } 

    public function installCustomerAddressAttributes($customerSetup) {

    } 

    public function getEavConfig() {
        return $this -> eavConfig;
    } 
}

Your Answer

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

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