Datepicker For Bootstrap : update bootstrap-datepicker - angularjs

I want to custom the footer of my bootstrap-datepicker, i want to remove the 3 buttons and do this:
JSFIDDLE
angular.module('ui.bootstrap.demo', ['ui.bootstrap']);
angular.module('ui.bootstrap.demo').controller('DatepickerDemoCtrl', function ($scope) {
$scope.today = function() {
$scope.dt = new Date();
};
$scope.today();
$scope.clear = function () {
$scope.dt = null;
};
// Disable weekend selection
$scope.disabled = function(date, mode) {
return ( mode === 'day' && ( date.getDay() === 0 || date.getDay() === 6 ) );
};
$scope.toggleMin = function() {
$scope.minDate = $scope.minDate ? null : new Date();
};
$scope.toggleMin();
$scope.open = function($event) {
$event.preventDefault();
$event.stopPropagation();
$scope.opened = true;
};
$scope.dateOptions = {
formatYear: 'yyyy',
startingDay: 1,
numberOfMonths: 2,
autoclose: true
};
$scope.formats = ['dd-MMMM-yyyy', 'yyyy/MM/dd', 'dd.MM.yyyy', 'shortDate'];
$scope.format = $scope.formats[0];
});

You can remove the current footer
show-button-bar='false'
And add a new div with ng-show if the calendar is opened
<div class="footer" ng-show="opened">Horaries:<button>1</button><button>2</button><button>3</button></div>
Here is an example:
http://plnkr.co/edit/8WvmM9AmS8x6iArJzZv8?p=preview
off course, You´ll need some CSS to make it look like you want

Related

Datepicker Angular bootstrap

I'm using angular-ui-bootstrap datepicker, and I want to use the following input format 'ddMMyyyy' on my input. Actually the ng-change is called when type this format in the input, but I want the input changes to the format to 'dd/MM/yyyy' after ng-change, just like when you select a date inside the datepicker calendar. How can I do that?
Here a plnkr example code
https://plnkr.co/edit/Njetw7fVfZATxruuUI3m?p=preview
angular.module('ui.bootstrap.demo', ['ngAnimate', 'ngSanitize', 'ui.bootstrap']);
angular.module('ui.bootstrap.demo').controller('DatepickerPopupDemoCtrl', function ($scope) {
$scope.today = function() {
$scope.dt = new Date();
};
$scope.today();
$scope.clear = function() {
$scope.dt = null;
};
$scope.inlineOptions = {
customClass: getDayClass,
minDate: new Date(),
showWeeks: true
};
$scope.dateOptions = {
dateDisabled: disabled,
formatYear: 'yy',
maxDate: new Date(2020, 5, 22),
minDate: new Date(),
startingDay: 1
};
// Disable weekend selection
function disabled(data) {
var date = data.date,
mode = data.mode;
return mode === 'day' && (date.getDay() === 0 || date.getDay() === 6);
}
$scope.toggleMin = function() {
$scope.inlineOptions.minDate = $scope.inlineOptions.minDate ? null : new Date();
$scope.dateOptions.minDate = $scope.inlineOptions.minDate;
};
$scope.toggleMin();
$scope.open1 = function() {
$scope.popup1.opened = true;
};
$scope.open2 = function() {
$scope.popup2.opened = true;
};
$scope.setDate = function(year, month, day) {
$scope.dt = new Date(year, month, day);
};
$scope.formats = ['dd-MMMM-yyyy', 'yyyy/MM/dd', 'dd.MM.yyyy', 'shortDate'];
$scope.format = $scope.formats[0];
$scope.altInputFormats = ['M!/d!/yyyy', 'ddMMyyyy'];
$scope.popup1 = {
opened: false
};
$scope.popup2 = {
opened: false
};
var tomorrow = new Date();
tomorrow.setDate(tomorrow.getDate() + 1);
var afterTomorrow = new Date();
afterTomorrow.setDate(tomorrow.getDate() + 1);
$scope.events = [
{
date: tomorrow,
status: 'full'
},
{
date: afterTomorrow,
status: 'partially'
}
];
function getDayClass(data) {
var date = data.date,
mode = data.mode;
if (mode === 'day') {
var dayToCheck = new Date(date).setHours(0,0,0,0);
for (var i = 0; i < $scope.events.length; i++) {
var currentDay = new Date($scope.events[i].date).setHours(0,0,0,0);
if (dayToCheck === currentDay) {
return $scope.events[i].status;
}
}
}
return '';
}
});

why does datepicker popup not display?

I am trying to create a bootstrap datapicker directive:
app.directive('datePicker', function ($compile, $timeout) {
return {
replace: true,
restrict:'E',
templateUrl: 'datepicker.html',
scope: {},
controller: function ($scope) {
console.log('datepciker');
// debugger;
$scope.today = function () {
$scope.dt = new Date();
};
$scope.today();
$scope.clear = function () {
$scope.dt = null;
};
// Disable weekend selection
//$scope.disabled = function(date, mode) {
// return ( mode === 'day' && ( date.getDay() === 0 || date.getDay() === 6 ) );
//};
$scope.toggleMin = function () {
$scope.minDate = $scope.minDate ? null : new Date();
};
$scope.toggleMin();
$scope.open = function ($event) {
$event.preventDefault();
$event.stopPropagation();
$scope.opened = true;
};
//$scope.open = function ($event) {
// $scope.status.opened = true;
//};
$scope.dateOptions = {
formatYear: 'yy',
startingDay: 1
};
$scope.formats = ['dd-MMMM-yyyy', 'yyyy/MM/dd', 'dd.MM.yyyy', 'shortDate'];
$scope.format = $scope.formats[0];
$scope.status = {
opened: false
};
var tomorrow = new Date();
tomorrow.setDate(tomorrow.getDate() + 1);
var afterTomorrow = new Date();
afterTomorrow.setDate(tomorrow.getDate() + 2);
$scope.events =
[
{
date: tomorrow,
status: 'full'
},
{
date: afterTomorrow,
status: 'partially'
}
];
$scope.getDayClass = function (date, mode) {
if (mode === 'day') {
var dayToCheck = new Date(date).setHours(0, 0, 0, 0);
for (var i = 0; i < $scope.events.length; i++) {
var currentDay = new Date($scope.events[i].date).setHours(0, 0, 0, 0);
if (dayToCheck === currentDay) {
return $scope.events[i].status;
}
}
}
return '';
};
}
};
In my page I have:
<date-picker ng-model="dateTo"></date-picker>
For some reason the popup does not come up, any suggestions on how to fix this?
plunkr:http://plnkr.co/edit/UiMiEk5GQSVId4YdAnCH?p=preview
Line 2 of datepicker.html ends in
is-open="status.opened"
If you change that to just is-open-"opened" you get a date picker.

why is there only 1 datepicker visible?

I have created a bootstrap datepicker:
app.directive('datePicker', function() {
return {
templateUrl: 'datepicker.html',
controller: function($scope){
console.log('it works');
$scope.today = function() {
$scope.dt = new Date();
};
$scope.today();
$scope.showWeeks = true;
$scope.toggleWeeks = function () {
$scope.showWeeks = ! $scope.showWeeks;
};
$scope.clear = function () {
$scope.dt = null;
};
// Disable weekend selection
$scope.disabled = function(date, mode) {
return ( mode === 'day' && ( date.getDay() === 0 || date.getDay() === 6 ) );
};
$scope.toggleMin = function() {
$scope.minDate = ( $scope.minDate ) ? null : new Date();
};
$scope.toggleMin();
$scope.open = function($event) {
$event.preventDefault();
$event.stopPropagation();
$scope.opened = true;
};
$scope.dateOptions = {
'year-format': "'yy'",
'starting-day': 1
};
$scope.formats = ['dd-MMMM-yyyy', 'yyyy/MM/dd', 'shortDate'];
$scope.format = $scope.formats[0];
console.log('end of controller');
}
};
});
When I place 2 of these directives on my page I only see 1 of them? Why is that?
How can I get 2 independent ones so I select 1 date in the first picker and another in the second one?
plunkr ref:http://plnkr.co/edit/QoiLt339m9x6pAswY0Kc?p=preview
Becouse you miss restrict:'E' property inside directive body.
To make them independent add scope:{} property it makes scope isolated.
http://plnkr.co/edit/aXW0zFR4t9kj75HxZ3kd?p=preview

How to display datepicker one at a time?

I am using datepicker from "http://angular-ui.github.io/bootstrap/"
In my page i am using more than one datepicker, So now i am able to open both at a time but what i exactly need is one datepicker at a time can any one suggest me an answer.
Code
angular.module('ui.bootstrap.demo').controller('DatepickerDemoCtrl',
function ($scope) {
$scope.today = function() {
$scope.dt = new Date();
};
$scope.today();
$scope.clear = function () {
$scope.dt = null;
};
// Disable weekend selection
$scope.disabled = function(date, mode) {
return ( mode === 'day' && ( date.getDay() === 0 || date.getDay() === 6 )
);
};
$scope.toggleMin = function() {
$scope.minDate = $scope.minDate ? null : new Date();
};
$scope.toggleMin();
$scope.open = function($event) {
$event.preventDefault();
$event.stopPropagation();
$scope.opened = true;
};
$scope.dateOptions = {
formatYear: 'yy',
startingDay: 1
};
$scope.formats = ['dd-MMMM-yyyy', 'yyyy/MM/dd', 'dd.MM.yyyy', 'shortDate'];
$scope.format = $scope.formats[0];
});

angular-UI datepicker apply date filter in controller

I am using angular-ui's datepicker, I used this datepicker in many places of my application , so I have to apply date filter in each controller. To avoid this I need to apply date filter in base date picker controller
like $scope.formData.order_date = $filter('date')($scope.formData.order_date, 'dd-MM-yyyy');
Base datepicker controller:
controller('DatepickerDemoCtrl', [
'$scope', function($scope) {
$scope.today = function() {
return $scope.dt = new Date();
};
$scope.today();
$scope.showWeeks = true;
$scope.toggleWeeks = function() {
return $scope.showWeeks = !$scope.showWeeks;
};
$scope.clear = function() {
return $scope.dt = null;
};
$scope.disabled = function(date, mode) {
return mode === 'day' && (date.getDay() === 0 || date.getDay() === 6);
};
$scope.toggleMin = function() {
var _ref;
return $scope.minDate = (_ref = $scope.minDate) != null ? _ref : {
"null": new Date()
};
};
$scope.toggleMin();
$scope.open = function($event,opened) {
$event.preventDefault();
$event.stopPropagation();
console.log($scope);
$scope[opened] = true;
};
$scope.dateOptions = {
'year-format': "'yy'",
'starting-day': 1
};
$scope.formats = ['dd-MM-yyyy', 'yyyy/MM/dd', 'shortDate'];
return $scope.format = $scope.formats[0];
}
])
How can I add common date filter in datepicker controller? Is it possible?
If it's just a basic date formatting you want to do, you can directly apply the "format-day", "format-month", and "format-year" elements on the datepicker tag itself. See the solution at this previously answered stackoverflow question: Angular bootstrap datepicker date format does not format ng-model value . See the documentation for more info: http://angular-ui.github.io/bootstrap/.

Resources