Add Color Picker in Magento 2 System Configuration

 

Color Picker Magento 2

Color Picker Magento 2

 

Tested in Magento version 2.2.4 and 2.2.5

I don’t know about all but in above Magento versions from the admin, if we go to the Store->Configuration and then check the View page source we can see below js

adminhtml/Magento/backend/en_US/Dotdigitalgroup_Email/js/node_modules/colpick/colpick.js

If you open the js you will know it’s a color picker js. So why not use the color picker js which is already loading on the page. No need to add any external JS or CSS.

My solution is as below.

Replace [Vendor] with your Namespace and [Module] with your Modulename.

[Vendor]/[Module]/etc/adminhtml/system.xml

For the color picker, all you need is add a field like below

Create [Vendor]/[Module]/Block/ColorPicker.php

That’s it. It solved my problem. So if that js is loading on the page It should definitely work. It is working for me.

No Comments

Post A Comment