-
-
Save HasAndries/3135128 to your computer and use it in GitHub Desktop.
angularjs directive for bootstrap datepicker : eternicode/bootstrap-datepicker, eyecon.ro
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('bDatepicker', []). | |
directive('bDatepicker', function(){ | |
return { | |
require: '?ngModel', | |
restrict: 'A', | |
link: function($scope, element, attrs, controller) { | |
var updateModel; | |
updateModel = function(ev) { | |
element.datepicker('hide'); | |
element.blur(); | |
return $scope.$apply(function() { | |
return controller.$setViewValue(ev.date); | |
}); | |
}; | |
if (controller != null) { | |
controller.$render = function() { | |
element.datepicker().data().datepicker.date = controller.$viewValue; | |
element.datepicker('setValue'); | |
element.datepicker('update'); | |
return controller.$viewValue; | |
}; | |
} | |
return attrs.$observe('bDatepicker', function(value) { | |
var options; | |
options = {}; | |
if (angular.isObject(value)) { | |
options = value; | |
} | |
if (typeof(value) === "string" && value.length > 0) { | |
options = angular.fromJson(value); | |
} | |
return element.datepicker(options).on('changeDate', updateModel); | |
}); | |
} | |
}; | |
}); |
@bluee did you ever have any luck getting options to work?
Check My Fork GIST
Check my simplified fork using momentjs and ES6 modules https://gist.github.com/MrSpider/a9c00eb652e4ed5e7c8cff5759f7438a
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Awesome post!! It might help you!
http://stackoverflow.com/questions/29389873/angularjs-custom-datepicker-directive
http://goo.gl/kLcijT