{"id":2560,"date":"2022-08-30T15:25:53","date_gmt":"2022-08-30T15:25:53","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/02\/03\/how-to-update-time-restraints-in-timepicker-plugin-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:25:53","modified_gmt":"2022-08-30T15:25:53","slug":"how-to-update-time-restraints-in-timepicker-plugin-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/how-to-update-time-restraints-in-timepicker-plugin-collection-of-common-programming-errors\/","title":{"rendered":"How to update Time Restraints in Timepicker plugin?-Collection of common programming errors"},"content":{"rendered":"<p>I&#8217;m using Timepicker plugin: http:\/\/trentrichardson.com\/examples\/timepicker\/ . I want to update Time Restraints after date was changed. This&#8217;s my code:<\/p>\n<pre><code>var date = \"10\/02\/2013\";  \/\/ October, 02 2013\nvar time = \"22:05\";\n$(\"#Date\").datepicker({\n                    minDate: 'today',\n                    maxDate: date,\n                    showOn: \"button\",\n                    buttonImage: '@Url.Content(\"~\/Images\/Library\/Calendar.png\")',\n                    buttonImageOnly: true,\n                    onSelect: function (dateText) {\n                        if (Date.parse(dateText) == Date.parse(date)) {\n                            $('#Time').timepicker({\n                                hourMax: time.split(':')[0],\n                                minuteMax: time.split(':')[1]\n                            });\n                        }\n                        else {\n\n                            $('#Time').timepicker({\n                                hourMax: 23,\n                                minuteMax: 59\n                            });\n                        }\n                    }\n                });\n<\/code><\/pre>\n<p>I try to do it, but it doesn&#8217;t work<\/p>\n<ol>\n<li>\n<p>You have given two undefined variables &#8216;date&#8217; and &#8216;time&#8217;, that probably you have defined elsewhere in the script (i assume) &#8230;<\/p>\n<p>Assuming that these vars are, for example:<\/p>\n<pre><code>var date = \"10\/02\/2013\";  \/\/ October, 02 2013\nvar time = \"22:05\";\n<\/code><\/pre>\n<p>your code should work (i&#8217;ve tested it).<\/p>\n<p>If you have a different date format you could try something like this:<\/p>\n<pre><code> var fdate = \"10\/02\/2013 22:05\";\n var date = fdate.split(' ')[0];\n var time = fdate.split(' ')[1];\n .....\n<\/code><\/pre>\n<\/li>\n<li>\n<p>I find a way to resolve my problem: When I choose another day I destroy timepicker and recreate it again.<\/p>\n<pre><code>var date = \"10\/02\/2013\";\nvar time = \"22:05\";\n$(\"#S-Date\").datepicker({\n                        minDate: 'today',\n                        maxDate: date,\n                        showOn: \"button\",\n                        buttonImage: '@Url.Content(\"~\/Images\/Library\/Calendar.png\")',\n                        buttonImageOnly: true,\n                        onSelect: function (dateText) {\n                            if (Date.parse(dateText) == Date.parse(date)) {\n                                $(\"#S-Time\").val(formatTime12(time));\n                                $('#S-Time').timepicker('destroy');\n                                $('#S-Time').timepicker({\n                                    hourMax: time.split(':')[0],\n                                    minuteMax: time.split(':')[1]\n                                });\n                            }\n                            else {\n                                $('#S-Time').timepicker('destroy');\n                                $('#S-Time').timepicker({\n                                    hourMax: 23,\n                                    minuteMax: 59\n                                });\n                            }\n                        }\n                    });\n<\/code><\/pre>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2014-02-03 02:28:10. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I&#8217;m using Timepicker plugin: http:\/\/trentrichardson.com\/examples\/timepicker\/ . I want to update Time Restraints after date was changed. This&#8217;s my code: var date = &#8220;10\/02\/2013&#8221;; \/\/ October, 02 2013 var time = &#8220;22:05&#8221;; $(&#8220;#Date&#8221;).datepicker({ minDate: &#8216;today&#8217;, maxDate: date, showOn: &#8220;button&#8221;, buttonImage: &#8216;@Url.Content(&#8220;~\/Images\/Library\/Calendar.png&#8221;)&#8217;, buttonImageOnly: true, onSelect: function (dateText) { if (Date.parse(dateText) == Date.parse(date)) { $(&#8216;#Time&#8217;).timepicker({ hourMax: time.split(&#8216;:&#8217;)[0], minuteMax: [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2560","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2560","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=2560"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2560\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=2560"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=2560"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=2560"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}