From a4835ec8ba69fa7a3bb6030ed6ed656e71ac1193 Mon Sep 17 00:00:00 2001 From: Jose Date: Thu, 21 Jul 2016 09:01:35 +0000 Subject: [PATCH] Fix bug when using an empty value and no defining placeholder --- source/ngComboDatePicker.js | 10 ++++++---- source/ngComboDatePicker.min.js | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/source/ngComboDatePicker.js b/source/ngComboDatePicker.js index 6022c8a..5b70629 100644 --- a/source/ngComboDatePicker.js +++ b/source/ngComboDatePicker.js @@ -1,5 +1,5 @@ /* - * ngComboDatePicker v1.2.2 + * ngComboDatePicker v1.2.3 * http://github.com/jfmdev/ngComboDatePicker * «Copyright 2015 Jose F. Maldonado» * License: LGPLv3 (http://www.gnu.org/licenses/lgpl-3.0.html) @@ -197,9 +197,11 @@ angular.module("ngComboDatePicker", []) $scope.month = ''; $scope.year = ''; - placeHolders[0].disabled = false; - placeHolders[1].disabled = false; - placeHolders[2].disabled = false; + if(placeHolders) { + placeHolders[0].disabled = false; + placeHolders[1].disabled = false; + placeHolders[2].disabled = false; + } } // Hide or show days and months according to the min and max dates. diff --git a/source/ngComboDatePicker.min.js b/source/ngComboDatePicker.min.js index d061d8a..ab28ba8 100644 --- a/source/ngComboDatePicker.min.js +++ b/source/ngComboDatePicker.min.js @@ -1,7 +1,7 @@ /* - * ngComboDatePicker v1.2.2 + * ngComboDatePicker v1.2.3 * http://github.com/jfmdev/ngComboDatePicker * «Copyright 2015 Jose F. Maldonado» * License: LGPLv3 (http://www.gnu.org/licenses/lgpl-3.0.html) */ -angular.module("ngComboDatePicker",[]).directive("ngComboDatePicker",function(){return{restrict:"AEC",scope:{ngModel:"=",ngDate:"@",ngMinDate:"@",ngMaxDate:"@",ngMonths:"@",ngOrder:"@",ngAttrsDate:"@",ngAttrsMonth:"@",ngAttrsYear:"@",ngYearOrder:"@",ngTimezone:"@",ngPlaceholder:"@"},controller:["$scope",function(e){function n(e,n){var a=null;return void 0!==e&&null!==e&&(e instanceof Date?a=e:("number"==typeof e||"string"==typeof e)&&(a=new Date(isNaN(e)?e:parseInt(e,10)),a=t(a,n))),a}function t(e,n){var t=isNaN(n)?(new Date).getTimezoneOffset():60*parseFloat(n);return new Date(e.getTime()+60*t*1e3)}function a(e,n){var t=31;return null!=e&&((4==e||6==e||9==e||11==e)&&(t=30),null!=n&&2==e&&(t=n%4==0&&n%100!=0?29:28)),t}function l(e){var n=null;if(null!=e){try{n=JSON.parse(e)}catch(t){}if(null==n)try{n=JSON.parse(e.replace(/'/g,'"'))}catch(t){}}return n}e.ngModel=n(e.ngModel,e.ngTimezone),e.ngAttrsDate=l(e.ngAttrsDate),e.ngAttrsMonth=l(e.ngAttrsMonth),e.ngAttrsYear=l(e.ngAttrsYear);var r=n(e.ngDate,e.ngTimezone);if(null!=r&&(e.ngModel=r),"string"!=typeof e.ngOrder?e.ngOrder="dmy":e.ngOrder=e.ngOrder.toLowerCase(),e.minDate=n(e.ngMinDate,e.ngTimezone),null==e.ngMinDate){var o=t(new Date,e.ngTimezone);e.minDate=new Date(o.getFullYear()-100,o.getMonth(),o.getDate(),o.getHours(),o.getMinutes(),o.getSeconds(),o.getMilliseconds())}e.maxDate=n(e.ngMaxDate,e.ngTimezone),null==e.maxDate&&(e.maxDate=t(new Date,e.ngTimezone)),e.ngModele.maxDate&&(e.ngModel=e.maxDate);var g=null;if(void 0!==e.ngPlaceholder&&null!==e.ngPlaceholder&&("string"==typeof e.ngPlaceholder||Array.isArray(e.ngPlaceholder))){var d="string"==typeof e.ngPlaceholder?e.ngPlaceholder.split(","):e.ngPlaceholder;if(3==d.length){g=[];for(var s=0;s=a;a++)e.months.push({value:a,name:u[a]})},e.updateDateList=function(){var n=1;null!=e.ngModel&&e.ngModel.getMonth()==e.minDate.getMonth()&&e.ngModel.getFullYear()==e.minDate.getFullYear()&&(n=e.minDate.getDate());var t=null!=e.ngModel?a(e.ngModel.getMonth()+1,e.ngModel.getFullYear()):a(null,null);null!=e.ngModel&&e.ngModel.getMonth()==e.maxDate.getMonth()&&e.ngModel.getFullYear()==e.maxDate.getFullYear()&&(t=e.maxDate.getDate()),e.dates=[],g&&e.dates.push(g[2]);for(var l=n;t>=l;l++)e.dates.push({value:l,name:l})},e.modelUpdated=function(){e.date=null!=e.ngModel?e.ngModel.getDate():"",e.month=null!=e.ngModel?e.ngModel.getMonth():"",e.year=null!=e.ngModel?e.ngModel.getFullYear():"",e.updateMonthList(),e.updateDateList()},e.$watch("ngModel",function(){e.modelUpdated()}),e.onChange=function(n){if(null!=e.date&&""!=e.date&&!isNaN(parseInt(e.month))&&null!=e.year&&""!=e.year){var t=a(e.month+1,e.year),l=0,r=0,o=0,d=0;null!=e.ngModel&&(l=e.ngModel.getHours(),r=e.ngModel.getMinutes(),o=e.ngModel.getSeconds(),d=e.ngModel.getMilliseconds()),e.ngModel=new Date(e.year,e.month,e.date>t?t:e.date,l,r,o,d)}g&&(""!=e.year&&(g[0].disabled=!0),""!=e.month&&(g[1].disabled=!0),""!=e.date&&(g[2].disabled=!0)),e.updateMonthList(),e.updateDateList()},e.getSomething=function(){return"color:red;"}}],link:function(e,n,t){var a=angular.element,l=a(n[0]).children(),r=e.ngOrder.split("");null!=e.ngAttrsDate&&a(l[0]).attr(e.ngAttrsDate),null!=e.ngAttrsMonth&&a(l[1]).attr(e.ngAttrsMonth),null!=e.ngAttrsYear&&a(l[2]).attr(e.ngAttrsYear);for(var o=0;o';return e}}}); +angular.module("ngComboDatePicker",[]).directive("ngComboDatePicker",function(){return{restrict:"AEC",scope:{ngModel:"=",ngDate:"@",ngMinDate:"@",ngMaxDate:"@",ngMonths:"@",ngOrder:"@",ngAttrsDate:"@",ngAttrsMonth:"@",ngAttrsYear:"@",ngYearOrder:"@",ngTimezone:"@",ngPlaceholder:"@"},controller:["$scope",function(e){function n(e,n){var a=null;return void 0!==e&&null!==e&&(e instanceof Date?a=e:("number"==typeof e||"string"==typeof e)&&(a=new Date(isNaN(e)?e:parseInt(e,10)),a=t(a,n))),a}function t(e,n){var t=isNaN(n)?(new Date).getTimezoneOffset():60*parseFloat(n);return new Date(e.getTime()+60*t*1e3)}function a(e,n){var t=31;return null!=e&&((4==e||6==e||9==e||11==e)&&(t=30),null!=n&&2==e&&(t=n%4==0&&n%100!=0?29:28)),t}function l(e){var n=null;if(null!=e){try{n=JSON.parse(e)}catch(t){}if(null==n)try{n=JSON.parse(e.replace(/'/g,'"'))}catch(t){}}return n}e.ngModel=n(e.ngModel,e.ngTimezone),e.ngAttrsDate=l(e.ngAttrsDate),e.ngAttrsMonth=l(e.ngAttrsMonth),e.ngAttrsYear=l(e.ngAttrsYear);var r=n(e.ngDate,e.ngTimezone);if(null!=r&&(e.ngModel=r),"string"!=typeof e.ngOrder?e.ngOrder="dmy":e.ngOrder=e.ngOrder.toLowerCase(),e.minDate=n(e.ngMinDate,e.ngTimezone),null==e.ngMinDate){var o=t(new Date,e.ngTimezone);e.minDate=new Date(o.getFullYear()-100,o.getMonth(),o.getDate(),o.getHours(),o.getMinutes(),o.getSeconds(),o.getMilliseconds())}e.maxDate=n(e.ngMaxDate,e.ngTimezone),null==e.maxDate&&(e.maxDate=t(new Date,e.ngTimezone)),e.ngModele.maxDate&&(e.ngModel=e.maxDate);var g=null;if(void 0!==e.ngPlaceholder&&null!==e.ngPlaceholder&&("string"==typeof e.ngPlaceholder||Array.isArray(e.ngPlaceholder))){var d="string"==typeof e.ngPlaceholder?e.ngPlaceholder.split(","):e.ngPlaceholder;if(3==d.length){g=[];for(var s=0;s=a;a++)e.months.push({value:a,name:u[a]})},e.updateDateList=function(){var n=1;null!=e.ngModel&&e.ngModel.getMonth()==e.minDate.getMonth()&&e.ngModel.getFullYear()==e.minDate.getFullYear()&&(n=e.minDate.getDate());var t=null!=e.ngModel?a(e.ngModel.getMonth()+1,e.ngModel.getFullYear()):a(null,null);null!=e.ngModel&&e.ngModel.getMonth()==e.maxDate.getMonth()&&e.ngModel.getFullYear()==e.maxDate.getFullYear()&&(t=e.maxDate.getDate()),e.dates=[],g&&e.dates.push(g[2]);for(var l=n;t>=l;l++)e.dates.push({value:l,name:l})},e.modelUpdated=function(){e.ngModel?(e.date=e.ngModel.getDate(),e.month=e.ngModel.getMonth(),e.year=e.ngModel.getFullYear()):(e.date="",e.month="",e.year="",g&&(g[0].disabled=!1,g[1].disabled=!1,g[2].disabled=!1)),e.updateMonthList(),e.updateDateList()},e.$watch("ngModel",function(){e.modelUpdated()}),e.onChange=function(n){if(null!=e.date&&""!=e.date&&!isNaN(parseInt(e.month))&&null!=e.year&&""!=e.year){var t=a(e.month+1,e.year),l=0,r=0,o=0,d=0;null!=e.ngModel&&(l=e.ngModel.getHours(),r=e.ngModel.getMinutes(),o=e.ngModel.getSeconds(),d=e.ngModel.getMilliseconds()),e.ngModel=new Date(e.year,e.month,e.date>t?t:e.date,l,r,o,d)}g&&(""!=e.year&&(g[0].disabled=!0),""!=e.month&&(g[1].disabled=!0),""!=e.date&&(g[2].disabled=!0)),e.updateMonthList(),e.updateDateList()},e.getSomething=function(){return"color:red;"}}],link:function(e,n,t){var a=angular.element,l=a(n[0]).children(),r=e.ngOrder.split("");null!=e.ngAttrsDate&&a(l[0]).attr(e.ngAttrsDate),null!=e.ngAttrsMonth&&a(l[1]).attr(e.ngAttrsMonth),null!=e.ngAttrsYear&&a(l[2]).attr(e.ngAttrsYear);for(var o=0;o';return e}}});