So date fields are added using Varien_Data_Form_Element_Date
. What you could do would be to look into this file and check the function getElementHtml
this is where the "magic" happens.
You should be able to call something like new Varien_Data_Form_Element_Date($config)
where $config
is the array used on the call to addElement
.
Note this is untested but "should" work
$element = new Varien_Data_Form_Element_Date(
array(
'name' => 'date',
'label' => Mage::helper('your_module_name')->__('Date'),
'after_element_html' => '<small>Comments</small>',
'tabindex' => 1,
'image' => $this->getSkinUrl('images/grid-cal.gif'),
'format' => Mage::app()->getLocale()->getDateFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT),
'value' => date(
Mage::app()->getLocale()->getDateStrFormat(Mage_Core_Model_Locale::FORMAT_TYPE_SHORT),
strtotime('next weekday')
)
)
);
$element->setId('date');
$element->getElementHtml(); // this should now give you all the html that you could need
Check out JSColor:
http://jscolor.com/
Its an open source and very easy to use Javascript library. All you have to do is import the library somewhere in your application, than you can simply create an input with the class "jscolor".
Get jscolor.js from above site and add inside Vendor/Modulename/view/adminhtml/web/js/jscolor.js
define js in your module xml head tag or create default.xml file inside Vendor/Modulename/view/adminhtml/layout/default.xml
<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<head>
<script src="Vendor_Modulename::js/jscolor.js"/>
</head>
</page>
Now set color picker in input like below:
$fieldset->addField('title_color', 'text', array(
'label' => __('Title Color'),
'class' => 'jscolor {hash:true,refine:false}',
'required' => false,
'name' => 'title_color',
));
This is working fine in magento 2.
Best Answer
Never mind guys, I resolved the problem.
Finally, add Colorpicker CSS inside your module and put it in the head tag
It's gonna work. You can see the color picker in your Admin Form.
Thanks :)