PHP Magento Tips

How to Add Color Picker In Magento Admin Grid in Custom Module

Rate this posting:
{[['']]}

It is very easy to add color picker In magento admin grid for your Custom Module. Just follow below step:

Step 1: Go to your Module Admin Form file and find field where you want to add color picker.

Example: Go in file app/code/community/mycompany/mymodule/Block/Adminhtml/entity_code/Edit/Tab/Form.php

(Go to your file with appropriate path)

and find $fieldset->addField function and pass class name parameter properly.

$fieldset->addField('backgroundcolor', 'text', array(

          'label'     => Mage::helper('mycompany_mymodule')->__('Background Color'),

          'name'      => 'backgroundcolor',

          'class'     => 'color {required:true, adjust:true, hash:true} validate-hex',

          'required'  => true,

        ));

here, 'class'     => 'color {required:true, adjust:true, hash:true} is important for color picker.

Now, in your adminhtml layout update file add jscolor.js javascript to initialize colorpicker.

And optionally add jquery-3.1.1.min.js if its not working.

<layout>
 <default>        
    <reference name="head">
    <action method="addJs">
         <script>yourmodulefolder/jquery-3.1.1.min.js</script><!--this is optional file // if not working then add this -->
    </action>
    <action method="addJs">
         <script>jscolor/jscolor.js</script>
    </action>
    </reference>      
    </default>
 ..............
</layout>

Hope This Post will help someone.

Thanks for reading.....👥
Tag : Magento
0 Comments On "How to Add Color Picker In Magento Admin Grid in Custom Module"

Back To Top