How to add a color picker to custom admin form in magento 2?

For our custom module we have developed in magento 2. Some time we need to add a color picker field in admin panel custom form. This is some thing pretty simple task to handle by adding some extra code set to our custom module.

Assume we already have a custom module and we want to add a color picker field on the form.

Adding the field in main.php. ( app/code/Ayakil/Faq/Block/Adminhtml/Module/Edit/Tab/Main.php)

Creating the Color.php file – ( app/code/Ayakil/Faq/Block/Adminhtml/Color.php )

Adding color-picker css in the custom module – ( app/code/Ayakil/Faq/view/adminhtml/layout/faq_index_edit.xml )

That’s all, you can see the color picker field in your admin panel custom form like below.

Color picker in Admin Form - Magento
Color picker in Admin Form – Magento

To view more articles visit the magento 2 section, graphql section

That’s it. Have a nice day.Enjoy coding , Learn , Experience , Teach and Help.

4 thoughts on “How to add a color picker to custom admin form in magento 2?”

  1. Outstanding post but I was wanting to know if you could write a litte more on this subject? I’d be very thankful if you could elaborate a little bit more. Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *