{"id":369,"date":"2016-02-28T22:01:35","date_gmt":"2016-02-28T16:31:35","guid":{"rendered":"http:\/\/www.magewallet.com\/?p=369"},"modified":"2020-03-13T16:09:41","modified_gmt":"2020-03-13T10:39:41","slug":"magento-2-add-calendar-admin-configuration-options","status":"publish","type":"post","link":"https:\/\/www.hiddentechies.com\/blog\/magento-2\/magento-2-add-calendar-admin-configuration-options\/","title":{"rendered":"Magento 2 &#8211; How to add calendar in admin configuration options?"},"content":{"rendered":"<p>Recently I have found one solution to add calendar in system configuration options. Lets discuss in detail.<\/p>\n<p>In order to add calendar in system configuration options, we have to add one system field and require one Block file.<\/p>\n<p>Use below code to add system field.<\/p>\n<pre class=\"lang:default decode:true \">&lt;field id=\"startdate\" translate=\"label\" type=\"text\" sortOrder=\"20\" showInDefault=\"1\" showInWebsite=\"1\" showInStore=\"1\"&gt;\r\n                    &lt;label&gt;Start Date&lt;\/label&gt;\r\n                    &lt;comment&gt;&lt;![CDATA[Date Format (Date\/Month\/Year)]]&gt;&lt;\/comment&gt;\r\n                    &lt;frontend_model&gt;Hiddentechies\\SytemCalendar\\Block\\Calendar&lt;\/frontend_model&gt;\r\n                &lt;\/field&gt;<\/pre>\n<p>Now lets create Block file &#8211; Calendar.php<\/p>\n<pre class=\"lang:default decode:true \">&lt;?php\r\n\r\nnamespace Hiddentechies\\SytemCalendar\\Block;\r\n\r\nuse Magento\\Framework\\Registry;\r\n\r\nclass Calendar extends \\Magento\\Config\\Block\\System\\Config\\Form\\Field {\r\n\r\n    \/**\r\n     * @var  Registry\r\n     *\/\r\n    protected $_coreRegistry;\r\n\r\n    \/**\r\n     * @param \\Magento\\Backend\\Block\\Template\\Context $context\r\n     * @param Registry $coreRegistry\r\n     * @param array $data\r\n     *\/\r\n    public function __construct(\r\n    \\Magento\\Backend\\Block\\Template\\Context $context, Registry $coreRegistry, array $data = []\r\n    ) {\r\n        $this-&gt;_coreRegistry = $coreRegistry;\r\n        parent::__construct($context, $data);\r\n    }\r\n\r\n    protected function _getElementHtml(\\Magento\\Framework\\Data\\Form\\Element\\AbstractElement $element) {\r\n        $baseURL = $this-&gt;getBaseUrl();\r\n        $html = $element-&gt;getElementHtml();\r\n        $calpath = $baseURL . 'pub\/media\/systemcalendar\/';\r\n        if (!$this-&gt;_coreRegistry-&gt;registry('datepicker_loaded')) {\r\n            $html .= '&lt;style type=\"text\/css\"&gt;input.datepicker { background-image: url(' . $calpath . 'calendar.png) !important; background-position: calc(100% - 8px) center; background-repeat: no-repeat; } input.datepicker.disabled,input.datepicker[disabled] { pointer-events: none; }&lt;\/style&gt;';\r\n            $this-&gt;_coreRegistry-&gt;registry('datepicker_loaded', 1);\r\n        }\r\n        $html .= '&lt;script type=\"text\/javascript\"&gt;\r\n            require([\"jquery\", \"jquery\/ui\"], function () {\r\n                jQuery(document).ready(function () {\r\n                    jQuery(\"#' . $element-&gt;getHtmlId() . '\").datepicker( { dateFormat: \"dd\/mm\/yy\" } );\r\n                        \r\n                    var el = document.getElementById(\"' . $element-&gt;getHtmlId() . '\");\r\n                    el.className = el.className + \" datepicker\";\r\n                });\r\n            });\r\n            &lt;\/script&gt;';\r\n        return $html;\r\n    }\r\n\r\n}<\/pre>\n<p>Lets discuss some terms used in this block.<br \/>\n<strong>Hiddentechies<\/strong> &#8211; Vendor Name<br \/>\n<strong>SytemCalendar<\/strong> &#8211; Module Name<br \/>\n<strong>calendar.png<\/strong> &#8211; add calendar icon image at <strong>pub\/media\/systemcalendar\/<\/strong> directory<\/p>\n<p>Thats it.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Recently I have found one solution to add calendar in system configuration options. Lets discuss in detail. In order to add calendar in system configuration options, we have to add one system field and require one Block file. Use below code to add system field. &lt;field id=&#8221;startdate&#8221; translate=&#8221;label&#8221; type=&#8221;text&#8221; sortOrder=&#8221;20&#8243; showInDefault=&#8221;1&#8243; showInWebsite=&#8221;1&#8243; showInStore=&#8221;1&#8243;&gt; &lt;label&gt;Start Date&lt;\/label&gt;&#8230; <\/p>\n<div class=\"actions\"><a href=\"https:\/\/www.hiddentechies.com\/blog\/magento-2\/magento-2-add-calendar-admin-configuration-options\/\">Continue Reading<\/a><\/div>\n","protected":false},"author":1,"featured_media":4892,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[59],"tags":[82,10,45,83],"_links":{"self":[{"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/posts\/369"}],"collection":[{"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/comments?post=369"}],"version-history":[{"count":3,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/posts\/369\/revisions"}],"predecessor-version":[{"id":10504,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/posts\/369\/revisions\/10504"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/media\/4892"}],"wp:attachment":[{"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/media?parent=369"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/categories?post=369"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/tags?post=369"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}