Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,18 @@
### 0.7.2
### 0.7.5

Minor bugfixes

### 0.7.4

Minor bugfixes

### 0.7.3

Several bugfixes

#### Features

* Added `mdp-disabled`

#### Breaking changes

Expand Down
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "mdPickers",
"version": "0.7.2",
"version": "0.7.5",
"homepage": "https://github.com/alenaksu/mdPickers",
"authors": [
"alenaksu"
Expand Down
47 changes: 30 additions & 17 deletions dist/mdPickers.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,7 +355,7 @@ function minDateValidator(value, format, minDate) {
return !value ||
angular.isDate(value) ||
!minDate.isValid() ||
date.isAfter(minDate);
date.isSameOrAfter(minDate);
}

function maxDateValidator(value, format, maxDate) {
Expand All @@ -365,7 +365,7 @@ function maxDateValidator(value, format, maxDate) {
return !value ||
angular.isDate(value) ||
!maxDate.isValid() ||
date.isBefore(maxDate);
date.isSameOrBefore(maxDate);
}

function filterValidator(value, format, filter) {
Expand All @@ -374,7 +374,11 @@ function filterValidator(value, format, filter) {
return !value ||
angular.isDate(value) ||
!angular.isFunction(filter) ||
filter(date);
!filter(date);
}

function requiredValidator(value, ngModel) {
return value
}

module.directive("mdpDatePicker", ["$mdpDatePicker", "$timeout", function($mdpDatePicker, $timeout) {
Expand All @@ -388,11 +392,11 @@ module.directive("mdpDatePicker", ["$mdpDatePicker", "$timeout", function($mdpDa
openOnClick = angular.isDefined(attrs.mdpOpenOnClick) ? true : false;

return '<div layout layout-align="start start">' +
'<md-button class="md-icon-button" ng-click="showPicker($event)">' +
'<md-button' + (angular.isDefined(attrs.mdpDisabled) ? ' ng-disabled="disabled"' : '') + ' class="md-icon-button" ng-click="showPicker($event)">' +
'<md-icon md-svg-icon="mdp-event"></md-icon>' +
'</md-button>' +
'<md-input-container' + (noFloat ? ' md-no-float' : '') + ' md-is-error="isError()">' +
'<input type="{{ ::type }}" aria-label="' + placeholder + '" placeholder="' + placeholder + '"' + (openOnClick ? ' ng-click="showPicker($event)" ' : '') + ' />' +
'<input type="{{ ::type }}"' + (angular.isDefined(attrs.mdpDisabled) ? ' ng-disabled="disabled"' : '') + ' aria-label="' + placeholder + '" placeholder="' + placeholder + '"' + (openOnClick ? ' ng-click="showPicker($event)" ' : '') + ' />' +
'</md-input-container>' +
'</div>';
},
Expand All @@ -403,7 +407,8 @@ module.directive("mdpDatePicker", ["$mdpDatePicker", "$timeout", function($mdpDa
"dateFormat": "@mdpFormat",
"placeholder": "@mdpPlaceholder",
"noFloat": "=mdpNoFloat",
"openOnClick": "=mdpOpenOnClick"
"openOnClick": "=mdpOpenOnClick",
"disabled": "=?mdpDisabled"
},
link: {
pre: function(scope, element, attrs, ngModel, $transclude) {
Expand Down Expand Up @@ -433,6 +438,8 @@ module.directive("mdpDatePicker", ["$mdpDatePicker", "$timeout", function($mdpDa
var date = angular.isDate(value) && moment(value);
if(date && date.isValid())
updateInputElement(date.format(scope.dateFormat));
else
updateInputElement(null);
});

ngModel.$validators.format = function(modelValue, viewValue) {
Expand All @@ -451,6 +458,10 @@ module.directive("mdpDatePicker", ["$mdpDatePicker", "$timeout", function($mdpDa
return filterValidator(viewValue, scope.dateFormat, scope.dateFilter);
};

ngModel.$validators.required = function(modelValue, viewValue) {
return angular.isUndefined(attrs.required) || !ngModel.$isEmpty(modelValue) || !ngModel.$isEmpty(viewValue);
};

ngModel.$parsers.unshift(function(value) {
var parsed = moment(value, scope.dateFormat, true);
if(parsed.isValid()) {
Expand All @@ -464,13 +475,11 @@ module.directive("mdpDatePicker", ["$mdpDatePicker", "$timeout", function($mdpDa
}
return parsed.toDate();
} else
return angular.isDate(ngModel.$modelValue) ? ngModel.$modelValue : null;
return null;
});

// update input element value
function updateInputElement(value) {
if(ngModel.$valid)
inputElement[0].size = value.length + 1;
inputElement[0].value = value;
inputContainerCtrl.setHasValue(!ngModel.$isEmpty(value));
}
Expand Down Expand Up @@ -512,7 +521,7 @@ module.directive("mdpDatePicker", ["$mdpDatePicker", "$timeout", function($mdpDa

scope.$on("$destroy", function() {
inputElement.off("reset input blur", onInputElementEvents);
})
});
}
}
};
Expand Down Expand Up @@ -577,7 +586,6 @@ function TimePickerCtrl($scope, $mdDialog, time, autoSwitch, $mdMedia) {
this.currentView = this.VIEW_HOURS;
this.time = moment(time);
this.autoSwitch = !!autoSwitch;
console.log(autoSwitch);

this.clockHours = parseInt(this.time.format("h"));
this.clockMinutes = parseInt(this.time.minutes());
Expand Down Expand Up @@ -739,7 +747,7 @@ module.directive("mdpClock", ["$animate", "$timeout", function($animate, $timeou
});

element.on("mouseup", function(e) {
element.off("mousemove", onEvent);
element.off("mousemove");
});

element.on("click", onEvent);
Expand Down Expand Up @@ -822,18 +830,19 @@ module.directive("mdpTimePicker", ["$mdpTimePicker", "$timeout", function($mdpTi
openOnClick = angular.isDefined(attrs.mdpOpenOnClick) ? true : false;

return '<div layout layout-align="start start">' +
'<md-button class="md-icon-button" ng-click="showPicker($event)">' +
'<md-button class="md-icon-button" ng-click="showPicker($event)"' + (angular.isDefined(attrs.mdpDisabled) ? ' ng-disabled="disabled"' : '') + '>' +
'<md-icon md-svg-icon="mdp-access-time"></md-icon>' +
'</md-button>' +
'<md-input-container' + (noFloat ? ' md-no-float' : '') + ' md-is-error="isError()">' +
'<input type="{{ ::type }}" aria-label="' + placeholder + '" placeholder="' + placeholder + '"' + (openOnClick ? ' ng-click="showPicker($event)" ' : '') + ' />' +
'<input type="{{ ::type }}"' + (angular.isDefined(attrs.mdpDisabled) ? ' ng-disabled="disabled"' : '') + ' aria-label="' + placeholder + '" placeholder="' + placeholder + '"' + (openOnClick ? ' ng-click="showPicker($event)" ' : '') + ' />' +
'</md-input-container>' +
'</div>';
},
scope: {
"timeFormat": "@mdpFormat",
"placeholder": "@mdpPlaceholder",
"autoSwitch": "=?mdpAutoSwitch",
"disabled": "=?mdpDisabled"
},
link: function(scope, element, attrs, ngModel, $transclude) {
var inputElement = angular.element(element[0].querySelector('input')),
Expand All @@ -859,12 +868,18 @@ module.directive("mdpTimePicker", ["$mdpTimePicker", "$timeout", function($mdpTi
var time = angular.isDate(value) && moment(value);
if(time && time.isValid())
updateInputElement(time.format(scope.timeFormat));
else
updateInputElement(null);
});

ngModel.$validators.format = function(modelValue, viewValue) {
return !viewValue || angular.isDate(viewValue) || moment(viewValue, scope.timeFormat, true).isValid();
};

ngModel.$validators.required = function(modelValue, viewValue) {
return angular.isUndefined(attrs.required) || !ngModel.$isEmpty(modelValue) || !ngModel.$isEmpty(viewValue);
};

ngModel.$parsers.unshift(function(value) {
var parsed = moment(value, scope.timeFormat, true);
if(parsed.isValid()) {
Expand All @@ -878,13 +893,11 @@ module.directive("mdpTimePicker", ["$mdpTimePicker", "$timeout", function($mdpTi
}
return parsed.toDate();
} else
return angular.isDate(ngModel.$modelValue) ? ngModel.$modelValue : null;
return null;
});

// update input element value
function updateInputElement(value) {
if(ngModel.$valid)
inputElement[0].size = value.length + 1;
inputElement[0].value = value;
inputContainerCtrl.setHasValue(!ngModel.$isEmpty(value));
}
Expand Down
2 changes: 1 addition & 1 deletion dist/mdPickers.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/mdPickers.min.js.map

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Should already be required, here for clarity
require('angular');

// Load Angular and dependent libs
require('angular-animate');
require('angular-aria');

// Now load Angular Material
require('angular-material');

require ('./dist/mdPickers');

module.exports = 'mdPickers';
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "mdPickers",
"version": "0.7.2",
"version": "0.7.5",
"description": "Material Design date/time pickers for Angular Material",
"main": "gulpfile.js",
"main": "index",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
Expand Down
29 changes: 19 additions & 10 deletions src/components/mdpDatePicker/mdpDatePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ function minDateValidator(value, format, minDate) {
return !value ||
angular.isDate(value) ||
!minDate.isValid() ||
date.isAfter(minDate);
date.isSameOrAfter(minDate);
}

function maxDateValidator(value, format, maxDate) {
Expand All @@ -304,7 +304,7 @@ function maxDateValidator(value, format, maxDate) {
return !value ||
angular.isDate(value) ||
!maxDate.isValid() ||
date.isBefore(maxDate);
date.isSameOrBefore(maxDate);
}

function filterValidator(value, format, filter) {
Expand All @@ -313,7 +313,11 @@ function filterValidator(value, format, filter) {
return !value ||
angular.isDate(value) ||
!angular.isFunction(filter) ||
filter(date);
!filter(date);
}

function requiredValidator(value, ngModel) {
return value
}

module.directive("mdpDatePicker", ["$mdpDatePicker", "$timeout", function($mdpDatePicker, $timeout) {
Expand All @@ -327,11 +331,11 @@ module.directive("mdpDatePicker", ["$mdpDatePicker", "$timeout", function($mdpDa
openOnClick = angular.isDefined(attrs.mdpOpenOnClick) ? true : false;

return '<div layout layout-align="start start">' +
'<md-button class="md-icon-button" ng-click="showPicker($event)">' +
'<md-button' + (angular.isDefined(attrs.mdpDisabled) ? ' ng-disabled="disabled"' : '') + ' class="md-icon-button" ng-click="showPicker($event)">' +
'<md-icon md-svg-icon="mdp-event"></md-icon>' +
'</md-button>' +
'<md-input-container' + (noFloat ? ' md-no-float' : '') + ' md-is-error="isError()">' +
'<input type="{{ ::type }}" aria-label="' + placeholder + '" placeholder="' + placeholder + '"' + (openOnClick ? ' ng-click="showPicker($event)" ' : '') + ' />' +
'<input type="{{ ::type }}"' + (angular.isDefined(attrs.mdpDisabled) ? ' ng-disabled="disabled"' : '') + ' aria-label="' + placeholder + '" placeholder="' + placeholder + '"' + (openOnClick ? ' ng-click="showPicker($event)" ' : '') + ' />' +
'</md-input-container>' +
'</div>';
},
Expand All @@ -342,7 +346,8 @@ module.directive("mdpDatePicker", ["$mdpDatePicker", "$timeout", function($mdpDa
"dateFormat": "@mdpFormat",
"placeholder": "@mdpPlaceholder",
"noFloat": "=mdpNoFloat",
"openOnClick": "=mdpOpenOnClick"
"openOnClick": "=mdpOpenOnClick",
"disabled": "=?mdpDisabled"
},
link: {
pre: function(scope, element, attrs, ngModel, $transclude) {
Expand Down Expand Up @@ -372,6 +377,8 @@ module.directive("mdpDatePicker", ["$mdpDatePicker", "$timeout", function($mdpDa
var date = angular.isDate(value) && moment(value);
if(date && date.isValid())
updateInputElement(date.format(scope.dateFormat));
else
updateInputElement(null);
});

ngModel.$validators.format = function(modelValue, viewValue) {
Expand All @@ -390,6 +397,10 @@ module.directive("mdpDatePicker", ["$mdpDatePicker", "$timeout", function($mdpDa
return filterValidator(viewValue, scope.dateFormat, scope.dateFilter);
};

ngModel.$validators.required = function(modelValue, viewValue) {
return angular.isUndefined(attrs.required) || !ngModel.$isEmpty(modelValue) || !ngModel.$isEmpty(viewValue);
};

ngModel.$parsers.unshift(function(value) {
var parsed = moment(value, scope.dateFormat, true);
if(parsed.isValid()) {
Expand All @@ -403,13 +414,11 @@ module.directive("mdpDatePicker", ["$mdpDatePicker", "$timeout", function($mdpDa
}
return parsed.toDate();
} else
return angular.isDate(ngModel.$modelValue) ? ngModel.$modelValue : null;
return null;
});

// update input element value
function updateInputElement(value) {
if(ngModel.$valid)
inputElement[0].size = value.length + 1;
inputElement[0].value = value;
inputContainerCtrl.setHasValue(!ngModel.$isEmpty(value));
}
Expand Down Expand Up @@ -451,7 +460,7 @@ module.directive("mdpDatePicker", ["$mdpDatePicker", "$timeout", function($mdpDa

scope.$on("$destroy", function() {
inputElement.off("reset input blur", onInputElementEvents);
})
});
}
}
};
Expand Down
18 changes: 11 additions & 7 deletions src/components/mdpTimePicker/mdpTimePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ function TimePickerCtrl($scope, $mdDialog, time, autoSwitch, $mdMedia) {
this.currentView = this.VIEW_HOURS;
this.time = moment(time);
this.autoSwitch = !!autoSwitch;
console.log(autoSwitch);

this.clockHours = parseInt(this.time.format("h"));
this.clockMinutes = parseInt(this.time.minutes());
Expand Down Expand Up @@ -169,7 +168,7 @@ module.directive("mdpClock", ["$animate", "$timeout", function($animate, $timeou
});

element.on("mouseup", function(e) {
element.off("mousemove", onEvent);
element.off("mousemove");
});

element.on("click", onEvent);
Expand Down Expand Up @@ -252,18 +251,19 @@ module.directive("mdpTimePicker", ["$mdpTimePicker", "$timeout", function($mdpTi
openOnClick = angular.isDefined(attrs.mdpOpenOnClick) ? true : false;

return '<div layout layout-align="start start">' +
'<md-button class="md-icon-button" ng-click="showPicker($event)">' +
'<md-button class="md-icon-button" ng-click="showPicker($event)"' + (angular.isDefined(attrs.mdpDisabled) ? ' ng-disabled="disabled"' : '') + '>' +
'<md-icon md-svg-icon="mdp-access-time"></md-icon>' +
'</md-button>' +
'<md-input-container' + (noFloat ? ' md-no-float' : '') + ' md-is-error="isError()">' +
'<input type="{{ ::type }}" aria-label="' + placeholder + '" placeholder="' + placeholder + '"' + (openOnClick ? ' ng-click="showPicker($event)" ' : '') + ' />' +
'<input type="{{ ::type }}"' + (angular.isDefined(attrs.mdpDisabled) ? ' ng-disabled="disabled"' : '') + ' aria-label="' + placeholder + '" placeholder="' + placeholder + '"' + (openOnClick ? ' ng-click="showPicker($event)" ' : '') + ' />' +
'</md-input-container>' +
'</div>';
},
scope: {
"timeFormat": "@mdpFormat",
"placeholder": "@mdpPlaceholder",
"autoSwitch": "=?mdpAutoSwitch",
"disabled": "=?mdpDisabled"
},
link: function(scope, element, attrs, ngModel, $transclude) {
var inputElement = angular.element(element[0].querySelector('input')),
Expand All @@ -289,12 +289,18 @@ module.directive("mdpTimePicker", ["$mdpTimePicker", "$timeout", function($mdpTi
var time = angular.isDate(value) && moment(value);
if(time && time.isValid())
updateInputElement(time.format(scope.timeFormat));
else
updateInputElement(null);
});

ngModel.$validators.format = function(modelValue, viewValue) {
return !viewValue || angular.isDate(viewValue) || moment(viewValue, scope.timeFormat, true).isValid();
};

ngModel.$validators.required = function(modelValue, viewValue) {
return angular.isUndefined(attrs.required) || !ngModel.$isEmpty(modelValue) || !ngModel.$isEmpty(viewValue);
};

ngModel.$parsers.unshift(function(value) {
var parsed = moment(value, scope.timeFormat, true);
if(parsed.isValid()) {
Expand All @@ -308,13 +314,11 @@ module.directive("mdpTimePicker", ["$mdpTimePicker", "$timeout", function($mdpTi
}
return parsed.toDate();
} else
return angular.isDate(ngModel.$modelValue) ? ngModel.$modelValue : null;
return null;
});

// update input element value
function updateInputElement(value) {
if(ngModel.$valid)
inputElement[0].size = value.length + 1;
inputElement[0].value = value;
inputContainerCtrl.setHasValue(!ngModel.$isEmpty(value));
}
Expand Down