-
-
Save KennyLisc/97d443f6b1139b7781d4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('angularApp'). | |
directive('dt', function(){ | |
return { | |
require: '?ngModel', | |
restrict: 'A', | |
link: function ($scope, element, attrs, controller) { | |
var updateModel, onblur; | |
if (controller !== null) { | |
updateModel = function () { | |
if (element.data("DateTimePicker").minViewMode === element.data("DateTimePicker").viewMode) { | |
element.data("DateTimePicker").hide(); | |
element.blur(); | |
} | |
}; | |
onblur = function () { | |
var date = element.datetimepicker().data("DateTimePicker").getDate(); | |
return $scope.$apply(function () { | |
return controller.$setViewValue(date); | |
}); | |
}; | |
controller.$render = function () { | |
var date = controller.$viewValue; | |
if (angular.isDefined(date) && date != null && moment.isMoment(date)) { | |
element.datetimepicker().data("DateTimePicker").setDate(date); | |
} else if (angular.isDefined(date)) { | |
throw new Error('ng-model value must be a Moment - currently it is a ' + typeof date + '.'); | |
} | |
return controller.$viewValue; | |
}; | |
} | |
return attrs.$observe('dt', function (value) { | |
var options; | |
options = { }; //<--- insert your own defaults here! | |
if (angular.isObject(value)) { | |
options = value; | |
} | |
if (typeof (value) === "string" && value.length > 0) { | |
options = angular.fromJson(value); | |
} | |
return element.datetimepicker(options).on('change.dp', updateModel).on('blur', onblur); | |
}); | |
} | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment