{"id":1108,"date":"2016-10-23T19:33:19","date_gmt":"2016-10-23T14:03:19","guid":{"rendered":"http:\/\/www.magewallet.com\/?p=1108"},"modified":"2020-03-13T16:04:46","modified_gmt":"2020-03-13T10:34:46","slug":"magento-2-add-jquery-calendar-custom-frontend-form","status":"publish","type":"post","link":"https:\/\/www.hiddentechies.com\/blog\/magento-2\/magento-2-add-jquery-calendar-custom-frontend-form\/","title":{"rendered":"Magento 2 &#8211; How to add jQuery calendar to custom frontend form?"},"content":{"rendered":"<p>Recently I have found one solution to add jQuery calendar to custom frontend form. Lets discuss in detail.<\/p>\n<p>In order to add jQuery calendar to custom frontend form, we have to add text input field to custom frontend form.<\/p>\n<p>As per below code create one new text input field inside form block.<\/p>\n<pre class=\"lang:default decode:true \">&lt;input type=\"text\" class=\"input-text required-entry\" id=\"txtcalendar\" name=\"txtcalendar\" aria-required=\"true\" &gt;<\/pre>\n<p>In order to bind jquery-ui calendar with above input field, add below jquery snippet.<\/p>\n<pre class=\"lang:default decode:true \">&lt;script&gt;\r\n     require([\r\n          \"jquery\",\r\n          \"mage\/calendar\"\r\n     ], function($){\r\n         $(\"#txtcalendar\").calendar({\r\n              buttonText:\"&lt;?php echo __('Select Date') ?&gt;\",\r\n         });\r\n       });\r\n&lt;\/script&gt;<\/pre>\n<p>If you want to add date ranges on front-end, then use below code.<\/p>\n<pre class=\"lang:default decode:true \">&lt;div class=\"field overview required\" data-role=\"filter-form\" id=\"date_range\"&gt;\r\n     &lt;span class=\"field-row\"&gt;\r\n         &lt;label for=\"date_from\"&gt;\r\n            &lt;span&gt;&lt;?php echo __('From') ?&gt;:&lt;\/span&gt;\r\n         &lt;\/label&gt;\r\n         &lt;input class=\"input-text required-entry\"\r\n                 type=\"text\"\r\n                 id=\"date_from\"\r\n                 name=\"from\"\r\n                 \/&gt;\r\n           &lt;span id=\"date_from_advice\"&gt;&lt;\/span&gt;\r\n       &lt;\/span&gt;\r\n\r\n       &lt;span class=\"field-row\"&gt;\r\n             &lt;label for=\"date_to\"&gt;\r\n                &lt;span&gt;&lt;?php echo __('To') ?&gt;:&lt;\/span&gt;\r\n             &lt;\/label&gt;\r\n             &lt;input class=\"input-text required-entry\"\r\n                    type=\"text\"\r\n                    id=\"date_to\"\r\n                    name=\"report_to\"\r\n                    \/&gt;\r\n             &lt;span id=\"date_to_advice\"&gt;&lt;\/span&gt;\r\n        &lt;\/span&gt;\r\n\r\n        &lt;script&gt;\r\n            require([\r\n                \"jquery\",\r\n                \"mage\/calendar\"\r\n            ], function($){\r\n\r\n               $(\"#date_range\").dateRange({\r\n                 buttonText:\"&lt;?php echo __('Select Date') ?&gt;\",\r\n                    from:{\r\n                        id:\"date_from\"\r\n                    },\r\n                    to:{\r\n                        id:\"date_to\"\r\n                    }\r\n               });\r\n            });\r\n        &lt;\/script&gt;\r\n&lt;\/div&gt;<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Recently I have found one solution to add jQuery calendar to custom frontend form. Lets discuss in detail. In order to add jQuery calendar to custom frontend form, we have to add text input field to custom frontend form. As per below code create one new text input field inside form block. &lt;input type=&#8221;text&#8221; class=&#8221;input-text&#8230; <\/p>\n<div class=\"actions\"><a href=\"https:\/\/www.hiddentechies.com\/blog\/magento-2\/magento-2-add-jquery-calendar-custom-frontend-form\/\">Continue Reading<\/a><\/div>\n","protected":false},"author":1,"featured_media":4821,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[59],"tags":[152,153,28,45],"_links":{"self":[{"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/posts\/1108"}],"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=1108"}],"version-history":[{"count":3,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/posts\/1108\/revisions"}],"predecessor-version":[{"id":10529,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/posts\/1108\/revisions\/10529"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/media\/4821"}],"wp:attachment":[{"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/media?parent=1108"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/categories?post=1108"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hiddentechies.com\/blog\/wp-json\/wp\/v2\/tags?post=1108"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}