Skip to content

Commit 69be5e6

Browse files
committed
Added support for minDate and maxDate
1 parent 2f3e72d commit 69be5e6

File tree

4 files changed

+23
-9
lines changed

4 files changed

+23
-9
lines changed

lib/pickadate/translations/sv_SE.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/bootstrap-example.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<!DOCTYPE html>
22
<html ng-app="test">
33
<head>
4+
<meta charset="utf-8">
45
<title>Boostrap Schema Form example</title>
56
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
67
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap-theme.min.css">
@@ -65,7 +66,7 @@ <h3>Schema</h3>
6566
angular.module('test',['schemaForm','ui.ace']);
6667

6768
function TestCtrl($scope){
68-
$scope.person = { favorite: 'NaN', date: '2014-06-03' };
69+
$scope.person = { favorite: 'NaN' };
6970

7071
$scope.schema = {
7172
"type": "object",
@@ -170,7 +171,7 @@ <h3>Schema</h3>
170171
{ key: "soulserial", placeholder: "ex. 666" }
171172
]
172173
},
173-
"date",
174+
{ key: "date", minDate: "2014-06-20" },
174175
{ key: "radio", type: "radios" },
175176
{ key: "radiobuttons", type: "radiobuttons" },
176177
{

src/directives/angular-pickdate.js

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,18 @@
11
angular.module('ng').directive('pickADate', function () {
2+
3+
//String dates for min and max is not supported
4+
//https://github.com/amsul/pickadate.js/issues/439
5+
//So strings we create dates from
6+
var formatDate = function(value) {
7+
//Strings or timestamps we make a date of
8+
if (angular.isString(value) || angular.isNumber(value)) {
9+
return new Date(value);
10+
}
11+
return value; //We hope it's a date object
12+
}
13+
14+
15+
216
return {
317
restrict: "A",
418
require: 'ngModel',
@@ -51,14 +65,11 @@ angular.module('ng').directive('pickADate', function () {
5165
return picker.get('select',attrs.format || defaultFormat);
5266
});
5367

54-
picker.set('min', scope.minDate ? scope.minDate : false);
55-
picker.set('max', scope.maxDate ? scope.maxDate : false);
56-
5768
//bind once.
5869
if (angular.isDefined(attrs.minDate)) {
5970
var onceMin = scope.$watch('minDate', function (value) {
6071
if (value) {
61-
picker.set('min', value);
72+
picker.set('min', formatDate(value));
6273
onceMin();
6374
}
6475
}, true);
@@ -67,7 +78,7 @@ angular.module('ng').directive('pickADate', function () {
6778
if (angular.isDefined(attrs.maxDate)) {
6879
var onceMax = scope.$watch('maxDate', function (value) {
6980
if (value) {
70-
picker.set('max', value);
81+
picker.set('max', formatDate(value));
7182
onceMax();
7283
}
7384
}, true);

src/directives/decorators/bootstrap/datepicker.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
ng-required="form.required"
99
schema-validate="form.schema"
1010
ng-model="$$value$$"
11-
pick-a-date />
11+
pick-a-date
12+
min-date="form.minDate"
13+
max-date="form.maxDate" />
1214

1315
<span class="help-block">{{ (hasError() && errorMessage(schemaError())) || form.description}}</span>
1416
</div>

0 commit comments

Comments
 (0)